登入界面java jsp_JSP登入界面(HTML+JavaBan)

运用JavaBean封装数据库,简单的JSP登入界面,我在看代码之前,先说下用到的文件,总共会用到5个文件。

1.index.jsp:登入成功界面(一个空文件)2.login.jsp:登入界面3. LoginACtion.jsp :登入判断,中间跳转界面

4.usres.java:用户名注册界面    5.ORMDBUtil.java:后台连接数据库

1.login.jsp

Insert title here

.thred{

}

function on_submit(){

if((form1.username.value!="admin")||(form1.userpassword.value!="admin"))

{

alter("账户或密码错误");

form1.username.focus();

return false;

}

学生选课管理系统后台管理登入

用户名:密 码:

2.LoginACtion.jsp

Insert title here

String name=request.getParameter("username");

String password=request.getParameter("userpassword");

String sql="select * from admin where username='"+name+"'and password= '"+password+"'";

ResultSet rs=db.Query(sql);

if(rs.next())

response.sendRedirect("index.jsp");

else

response.sendRedirect("login.jsp");

%>

3.usres.java

package com.po;

public class usres {

private String username ;

private String password ;

public usres(){}

{}

public String getUsername() {

return username;

}

public void setUsername(String username) {

this.username = username;

}

public String getPassword() {

return password;

}

public void setPassword(String password) {

this.password = password;

}

}

4.ORMDBUtil.java

package com.po;

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 java.util.ArrayList;

public class ORMDBUtil {

/**

*

* @return

* @throws SQLException

* @throws ClassNotFoundException

* @throws ClassNotFoundException

*/

public Connection getConnection() throws SQLException,

InstantiationException,IllegalAccessException,

ClassNotFoundException{

Connection conn = null;

Class.forName( "com.microsoft.sqlserver.jdbc.SQLServerDriver");

String url= "jdbc:sqlserver://localhost:1433;DatabaseName=student ";

String user = "sa";

String password = "12345";

conn = DriverManager.getConnection(url, user, password);

return conn;

}

/**

*

* @param sql

* @return

* @throws Exception

*/

@SuppressWarnings("rawtypes")

public ResultSet Query(String sql){

Connection conn = null;

Statement stmt = null;

ResultSet rs = null;

try {

conn = getConnection();

} catch (InstantiationException | IllegalAccessException

| ClassNotFoundException | SQLException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

try {

stmt = conn.createStatement();

} catch (SQLException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

try {

rs = stmt.executeQuery(sql);

} catch (SQLException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

return rs;

}

}

你可能感兴趣的:(登入界面java,jsp)