学校网站java代码 学院网站代码

java怎么通过代码登入教务系统我使用几系统都B/S结构每登录都需要输入用户名密码觉非麻烦考虑其同事需求妨写自登录程序吧前考虑使用单点登录几经尝试放弃
我习惯使用Java本能始寻找Java解决Google输入Java自登录、Java网页模拟登录、Java Post 登录结倒少内容差我尝试终究没达我预期目标我都知道些代码应该jsp页面执行c/s结构程序执行些代码确实管用
我先析代码
String surl = "";
URL url = new URL(surl);
URLConnection conn = url.openConnection();
conn.setDoOutput(true);
OutputStreamWriter out=new OutputStreamWriter(conn.getOutputStream());
String str = "username=yournamepassword=123456";
out.write(str);
out.flush();
out.close();
C/S结构且参数确程序能够功登录oa系统要看结通面代码系统服务器返结System.out.println()
String sling = "";
String scontent = "";
BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream(),"UTF-8"));
while ((sling = in.readLine()) != null)
scontent= in"\r\n";
System.out.println(scontent);
C/S结构控制台输返值返内容看程序已经功登录要网址浏览器打重新登录问题没根本解决恶意注册应该达目
看C/S结构容易实现网页程序自登录除非C/S程序内嵌浏览器直接浏览器自访问系统应该没别主要问题于我没办共享Session
便于共享Session我能浏览器实现网页自登录通面代码jsp页面测试达预期目标
网页自登录希望程序自填充用户名密码Post式提交给登录页面Form所指向action页面或我系统登录页面源代码保存网页usernamepassword文本框设置默认值通网页登录系统测试发现行接能已经想解决
我通url.openConnection()建立连接返scontent打印接着打印代码:
out.println("\r\n");
原理简单通login.jsp登录页面全部源代码写前页面使用javascript脚本用户名密码值填充提交表单终于实现自登录目标现我通特殊网址例自访问oa
能注意参数url值经加密内容用户名密码加效期即效期内链接才效才实现自登录
老师要求用Java写一个程序,能够实现对我们学校的网站服务器的访问 。的确,这个是WebService的应用 。学校提供了规范,学校网站java代码你根据他的规范传入参数查询就可以了 。
你可以查下WebService相关的资料,以及编程技巧 。学校网站java代码我给你提供一个最原始的代码范本,是基于JDK的 。非第三方包 。其它的以次类推 。代码是无参的WebService请求,有参数的 , 可以自己拼接下 。当然现在有很多第三方包,都对访问代码做了封装,你也可以看一下 。
思路上:
1、通过服务器的WebService功能接口的访问格式及返回值格式组装HTTP请求 。
2、得到返回值 , 解析出自己要的数据并加以使用 。
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Document;
public class WebServiceGetter {
static final String urlString = "";
public static void helloVonProject() throws Exception {
URL url = new URL(urlString);
URLConnection connection = url.openConnection();
connection.setDoInput(true);
connection.setDoOutput(true);
connection
.setRequestProperty("Content-Type", "text/xml; charset=utf-8");
connection.setRequestProperty("SOAPAction",
"");
connection
.getOutputStream()
.write(("?xml version=\"1.0\" encoding=\"utf-8\"?\n"
"soap:Envelope xmlns:xsi=\"\" xmlns:xsd=\"\" xmlns:soap=\"\"\n"
"soap:Body\n"
"HelloVonProject xmlns=\"\" /\n"
"/soap:Body\n""/soap:Envelope").getBytes());
InputStream is = connection.getInputStream();
Document document = DocumentBuilderFactory.newInstance()
.newDocumentBuilder().parse(is);
System.out.println(document
.getElementsByTagName("HelloVonProjectResult").item(0)
.getFirstChild().getNodeValue());
}
public static void main(String[] args) throws Exception {
helloVonProject();
}
}
登录界面的java代码,分别有教师登录,管理员登录 , 学生登录,右边是用户名和密码,见图 。分三个包,自己建个包,导进去就ok了 , 数据库是access的 。
package 登录;
import java.awt.EventQueue;
public class Cilent {
private JFrame frame;
private JTextField textField;
private JPasswordField passwordField;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Cilent window = new Cilent();
window.frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the application.
*/
public Cilent() {
initialize();
}
【学校网站java代码 学院网站代码】 /**
* Initialize the contents of the frame.
*/
private void initialize() {
frame = new JFrame();
frame.setTitle("登陆界面");
frame.setBounds(100, 100, 450, 300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().setLayout(null);
frame.setResizable(false);
JLabel lblNewLabel = new JLabel("用户名");
lblNewLabel.setBounds(38, 43, 80, 34);
frame.getContentPane().add(lblNewLabel);
textField = new JTextField();
textField.setBounds(155, 42, 227, 37);
frame.getContentPane().add(textField);
textField.setColumns(10);
JLabel label = new JLabel("密 码");
label.setBounds(38, 115, 80, 34);
frame.getContentPane().add(label);
passwordField = new JPasswordField();
passwordField.setBounds(155, 115, 227, 37);
frame.getContentPane().add(passwordField);
JButton btnNewButton = new JButton("登 录");
btnNewButton.setBounds(60, 187, 115, 34);
frame.getContentPane().add(btnNewButton);
btnNewButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
// TODO Auto-generated method stub
UserCheck UC=new UserCheck(textField.getText(),String.valueOf(passwordField.getPassword()));
if(UC.getI()!=0)//有此用户
{
frame.setVisible(false);
}
else
{
textField.setText("");
passwordField.setText("");
}
}
});
JButton button = new JButton("取 消");
button.setBounds(242, 187, 115, 34);
frame.getContentPane().add(button);
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
// TODO Auto-generated method stub
textField.setText("");
passwordField.setText("");
}
});
}
}
/*****************************************************************/
package 登录;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import 操作处理.UsersCL;
/**@author 20111024
* 检测登录的用户在数据库中有无,若没有 , 则提示没有此用户,
* 若有 , 则判断级别:普通用户还是管理员 。
*/
public class UserCheck {
private int i=0;//用户级别:0不是用户、1是管理员、2是普通用户
UserCheck(String name ,String password)
{
String jdriver="sun.jdbc.odbc.JdbcOdbcDriver";
String connectDB="jdbc:odbc:Students";
Statement stmt=null;
ResultSet rs=null;
Connection con=null;
try {
Class.forName(jdriver);
con=DriverManager.getConnection(connectDB);
stmt=con.createStatement();
String query="select * from users where name='" name "' and passwd='" password "'";
rs=stmt.executeQuery(query);
if(rs.next())
{
//数据库中有此用户,访问成功
i=Integer.parseInt(rs.getString(3));
UsersCL UL=new UsersCL(i);
}
else
{
i=0;//没有用户是默认是0级
}
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public int getI() {
return i;
}
}
/********************************************************************************************/
package 操作处理;
import java.awt.EventQueue;
public class UsersCL implements ActionListener{
private JFrame frame;
private JTextField textField;
private JTextField textField_1;
private JTextField textField_2;
private JTextField textField_3;
private int i=0;
private JLabel label_3;
private JTextField textField_4;
public UsersCL(int i) {
this.i=i;
frame = new JFrame();
frame.setTitle("用户处理界面");
frame.setBounds(100, 100, 450, 300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().setLayout(null);
frame.setResizable(false);
frame.setVisible(true);
JLabel lblNewLabel = new JLabel("学 号");
lblNewLabel.setBounds(24, 32, 74, 29);
frame.getContentPane().add(lblNewLabel);
JLabel label = new JLabel("姓 名");
label.setBounds(24, 71, 74, 29);
frame.getContentPane().add(label);
JLabel label_1 = new JLabel("年 龄");
label_1.setBounds(24, 110, 74, 29);
frame.getContentPane().add(label_1);
label_3 = new JLabel("性 别");
label_3.setBounds(24, 149, 74, 29);
frame.getContentPane().add(label_3);
JLabel label_2 = new JLabel("状 态");
label_2.setBounds(24, 195, 74, 29);
frame.getContentPane().add(label_2);
textField = new JTextField();
textField.setBounds(101, 34, 113, 25);
frame.getContentPane().add(textField);
textField.setColumns(10);
textField_1 = new JTextField();
textField_1.setColumns(10);
textField_1.setBounds(101, 73, 113, 25);
frame.getContentPane().add(textField_1);
textField_2 = new JTextField();
textField_2.setColumns(10);
textField_2.setBounds(101, 112, 113, 25);
frame.getContentPane().add(textField_2);
textField_3 = new JTextField();
textField_3.setEditable(false);
textField_3.setColumns(10);
textField_3.setBounds(101, 199, 288, 25);
frame.getContentPane().add(textField_3);
textField_4 = new JTextField();
textField_4.setColumns(10);
textField_4.setBounds(101, 149, 113, 25);
frame.getContentPane().add(textField_4);
if(1==i)
{
JButton btnNewButton = new JButton("追 加");
btnNewButton.setBounds(276, 41, 113, 29);
frame.getContentPane().add(btnNewButton);
btnNewButton.addActionListener(this);
btnNewButton.setActionCommand("追加");
JButton button_1 = new JButton("删 除");
button_1.setBounds(276, 145, 113, 29);
frame.getContentPane().add(button_1);
button_1.addActionListener(this);
button_1.setActionCommand("删除");
}
JButton button = new JButton("查 询");
button.setBounds(276, 91, 113, 29);
frame.getContentPane().add(button);
button.addActionListener(this);
button.setActionCommand("查询");
}
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
String name,age,sex,query=null;
int num,age1,count=0;
num=Integer.parseInt(textField.getText());
name=textField_1.getText();
age1=Integer.parseInt(textField_2.getText());
sex=textField_4.getText();
if(e.getActionCommand().equals("追加"))
{
query="insert into students values(" num "," "'" name "'," age1 ",'" sex "');";
count=1;
}
else if(e.getActionCommand().equals("查询"))
{
query="select * from students where XSB=" num ";";
count=2;
}
else if(e.getActionCommand().equals("删除"))
{
query="delete from students where XSB=" num " and name=" "'" name "'";
count=3;
}
Statement stmt=null;
ResultSet rs=null;
Connection con=null;
String jdriver="sun.jdbc.odbc.JdbcOdbcDriver";
String connectDB="jdbc:odbc:Students";
String query1=null;
try {
Class.forName(jdriver);
con=DriverManager.getConnection(connectDB);
stmt=con.createStatement();
if(count==1)
{
query1="select * from students where XSB=" num ";";
rs=stmt.executeQuery(query1);
if(rs.next())
textField_3.setText("已经由此记录,不能追加!");
else
{
stmt.executeUpdate(query);
textField_3.setText("已经追加完成!");
}
}
else if(2==count)
{
stmt.executeQuery(query);
rs=stmt.executeQuery(query);
if(rs.next())
{
textField_3.setText("已查找到此记录!");
}
else
{
textField_3.setText("没有此记录 , 可以追加!");
}
}
else if(3==count)
{
query1="select * from students where XSB=" num " and name=" "'" name "'";
rs=stmt.executeQuery(query1);
if(rs.next())
{
stmt.executeUpdate(query);
textField_3.setText("已删除此记录!");
}
else
textField_3.setText("无此记录!");
}
} catch (ClassNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
finally{
//关闭资源
if(stmt!=null){
try {
stmt.close();
} catch (Exception e2) {
// TODO: handle exception
}
stmt=null;
}
if(con!=null){
try {
con.close();
} catch (Exception e2) {
// TODO: handle exception
}
con=null;
}
}
}
}
学校网站java代码的介绍就聊到这里吧 , 感谢你花时间阅读本站内容 , 更多关于学院网站代码、学校网站java代码的信息别忘了在本站进行查找喔 。

    推荐阅读