JSP简单的页面登录验证问题
利欲熏心 2014-12-09 04:52:08 <%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<%@ page
import="com.mysql.jdbc.*,java.sql.Connection, java.sql.DriverManager,java.sql.PreparedStatement,java.sql.ResultSet "%>
<html>
<body>
<%
String name = (String) request.getParameter("name");//读取用户界面输入
String psd = (String) request.getParameter("password");//读取用户界面输入密码
Class.forName("com.mysql.jdbc.Driver"); //加载驱动
Connection conn = DriverManager.getConnection(
"jdbc:mysql://localhost:3306/test", "root", "root");//创建连接
String sql = "select id , username, password from scy where name = '"
+ name + "' and password='" + psd + "'";
PreparedStatement pstmt = null;
ResultSet rs = null;
boolean flag = false;
try {
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery();//查询
while (rs.next()) { //遍历查询结构,现实在页面中
out.print(flag);
flag = true;
out.print(flag);
break;
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (rs != null)rs.close();
if (pstmt != null)pstmt.close();
if (conn != null)conn.close();
} catch (Exception e) {
e.printStackTrace();
}
}
if (flag) {
out.print(flag);
request.getRequestDispatcher("Login_yes.jsp").forward(request,response);
} else {
request.getRequestDispatcher("Login_No.jsp").forward(request,response);
}
%>
</body>
</html>
不管如何,都是跳转错误页面是为什么