以下是登陆界面源码 <%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> <%@ page import="java.sql.*"%> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <base href="<%=basePath%>"> <title>登陆页面</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> <!-- <link rel="stylesheet" type="text/css" href="styles.css"> --> </head> <body> <% String userid = new String(request.getParameter("username").getBytes("ISO-8859-1"),"GBK"); String password = new String(request.getParameter("password").getBytes("ISO-8859-1"),"GBK"); if ( userid == "" || userid == null || userid.length()>20 || password == "" || password == null || password.length()>20 ) { try { response.sendRedirect ( "wrong.jsp?wrongid=1" ); } catch ( Exception e ) { } } else{ Connection conn = null; Statement stmt = null; ResultSet rs = null; try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance(); conn =DriverManager.getConnection("jdbc:odbc:student"); stmt = conn.createStatement(); String sql="SELECT * FROM denglu where id="+userid+" and pw="+password; if (stmt.execute(sql)) { rs = stmt.getResultSet(); while(rs.next()){ out.println("登陆成功!<br />"); out.println("欢迎您:"+rs.getString("name")); } } conn.close(); } catch (SQLException ex){ response.sendRedirect ( "wrong.jsp?wrongid=2" ); } catch (InstantiationException e) { response.sendRedirect ( "wrong.jsp?wrongid=2" ); } catch (IllegalAccessException e) { response.sendRedirect ( "wrong.jsp?wrongid=2" ); } catch (ClassNotFoundException e) { response.sendRedirect ( "wrong.jsp?wrongid=2" ); } finally { if (rs != null) { try { rs.close(); } catch (SQLException sqlEx) { } // ignore rs = null; } if (stmt != null) { try { stmt.close(); } catch (SQLException sqlEx) { } // ignore stmt = null; } } } %> </body> </html> Access数据库 编号 id pw 1 admin 11 2 11 11 但输入账号admin 密码11 却进不去,为什么,求教。 |
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) | 黑马程序员IT技术论坛 X3.2 |