?? loginlogic.jsp
字號:
<%@page import="java.sql.*"%>
<%@page import="javax.servlet.*"%>
<html>
<head>
<title></title>
</head>
<body>
<%@ page contentType="text/html; charset=GBK" %>
<%request.setCharacterEncoding("GBK");%>
<%
String driver= "sun.jdbc.odbc.JdbcOdbcDriver";
Class.forName(driver).newInstance();
String ConURL = "jdbc:odbc:login";
Connection con = null;
con = DriverManager.getConnection(ConURL,"sa","453558337");
Statement stmt = con.createStatement();
String username=request.getParameter("Username");
String password=request.getParameter("Password");
String userkinds=request.getParameter("userkinds");
if(username.equals("")||password.length()==0){
String redirctURL="login.jsp";
response.sendRedirect(response.encodeURL(redirctURL));
}
else if(userkinds.trim().equals(""))out.print("<script>alert('請選擇用戶類型!');window.location.href='login.jsp'</script>");
else{
String sqlstring="SELECT Username,Password userkinds FROM logstu";
sqlstring+=" ";
sqlstring+="WHERE Username LIKE'"+username+"'";
ResultSet rs=null;
rs=stmt.executeQuery(sqlstring);
if(rs.next()){
if((rs.getString(2).trim().equals(password.trim()))&&(rs.getString(3).equals(userkinds))){
rs.close();
stmt.close();
con.close();
if(userkinds.trim().equals(user)) String redirctURL="success.jsp";
else String redirctURL="welcome.jsp";
response.sendRedirect(response.encodeURL(redirctURL));
}
else if(!(rs.getString(3).equals(userkinds))){
out.print("<script>alert('用戶類型不正確!');window.location.href='login.jsp'</script>");
}
else{
rs.close();
stmt.close();
con.close();
String redirctURL="login.jsp";
out.print("<script>alert('密碼錯誤!');window.location.href='login.html'</script>");
/*response.sendRedirect(response.encodeURL(redirctURL)); */
}
}
else{
rs.close();
stmt.close();
con.close();
out.print("<script>alert('用戶名不存在,請先注冊');window.location.href='register.html'</script>");
/*String redirctURL="login.jsp";
response.sendRedirect(response.encodeURL(redirctURL));*/
}
}
%>
</body>
</html>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -