checklogin.jsp

来自「--- --^_^-------------- 广师公寓中心 1.请装上」· JSP 代码 · 共 49 行

JSP
49
字号
<%@page contentType="text/html;charset=gb2312"%>
<%@page import="java.sql.*"%>
<% 
  String strusername=request.getParameter("textfield2");
  String struserpass=request.getParameter("textfield3");
%>  
<html>
<body background="images/background.gif">
<%
try{  
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException e)
{  
out.print(e);
}try{  
String strDirPath=application.getRealPath(request.getRequestURI()); 
strDirPath=strDirPath.substring(0,strDirPath.lastIndexOf('\\'))+"\\";  
strDirPath=application.getRealPath("ODBC/gongyu.mdb");  
String url = "jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ="+strDirPath; 
Connection conn = DriverManager.getConnection(url);  
Statement stmt = conn.createStatement();  
String sql="SELECT * FROM main where name='"+strusername+"' and pass='"+struserpass+"'";
ResultSet rs = stmt.executeQuery(sql);  
while(rs.next()){    
session.setAttribute("login","ok");
session.setAttribute("username",strusername);
session.setAttribute("userpass",struserpass);
%>
<jsp:forward page="hd.jsp"/>
<%    
}  
rs.close();  
stmt.close();  
conn.close();
}
catch(Exception ex)
{
out.print(ex);
}
%>
<%
out.println("<Script>");
out.println("alert('用户名或密码错误!')");
out.println("</Script>");
%>
<div align="center"><jsp:include page="login.jsp"/></div>
</body>
</html>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?