用Jsp做的一个简单的登陆界面,连接Mysql,数据库名字为school,表为user。
主要分为四个Jsp界面:index.jsp登陆界面,check.jsp检验页面,main.jsp登陆成功界面,error.jsp登陆失败界面。 如下所示:
<%@ page language=\ import=\ pageEncoding=\%>
<%
String username = new String(request.getParameter(\).getBytes(\),\);
String password = new String(request.getParameter(\).getBytes(\),\);
session.setAttribute(\,username); Connection dbconn = null; Statement stmt = null; ResultSet rs = null;
if(username.equals(\)){ response.sendRedirect(\); } try{
String driver = \;
String url = \; String user = \;
String Password = \; Class.forName(driver);
dbconn = DriverManager.getConnection(url, user, Password);
stmt = dbconn.createStatement();
String sql1 = \* from user where username='\+username+\;
rs = stmt.executeQuery(sql1); if(rs.next()){
//String sql2 = \password='\
//rs = stmt.executeQuery(sql2);
//判断用户密码是否正确 String userpass = rs.getString(\);
if(userpass.equals(password)){
response.sendRedirect(\); }
else{
response.sendRedirect(\); } }
else{
response.sendRedirect(\);
} }catch(Exception e){ e.printStackTrace(); }
finally{
rs.close(); stmt.close(); dbconn.close(); } %>
<%@ page language=\ import=\ import=\ pageEncoding=\%>
Date now = new Date(); DateFormat mediumDateFormat = DateFormat.getDateTimeInstance( DateFormat.MEDIUM, DateFormat.MEDIUM); %>