<%@ page language="java" import="java.util.*,java.sql.*" pageEncoding="GBK"%>
<%
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>My JSP 'login_conf.jsp' starting page</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>
<center>
<h1>留言管理范例 —— JSP + JDBC实现</h1>
<hr>
<br>
<%!
String DBDRIVER = "com.mysql.jdbc.Driver" ;
String DBURL = "jdbc:mysql://localhost:3306:abccs" ;
String DBUSER = "root" ;
String DBPASSWORD = "19890817" ;
Connection conn = null ;
PreparedStatement pstmt = null ;
ResultSet rs = null ;
%>
<%
// 声明一个boolean变量,用于保存用户是否合法的状态
boolean flag = false ;
// 接收参数
String id = request.getParameter("id") ;
String password = request.getParameter("password") ;
%>
<%
String sql = "SELECt name FROM person WHERe id=? and password=?" ;
try
{
Class.forName(DBDRIVER) ;
conn = DriverManager.getConnection(DBURL,DBUSER,DBPASSWORD) ;
pstmt = conn.prepareStatement(sql) ;
pstmt.setString(1,id) ;
pstmt.setString(3,password) ;
rs = pstmt.executeQuery() ;
if(rs.next())
{
// 用户合法
flag = true ;
// 将用户名保存在session之中
session.setAttribute("uname",rs.getString(1)) ;
}
else
{
// 保存错误信息
request.setAttribute("err","错误的用户名及密码!!!") ;
}
rs.close() ;
pstmt.close() ;
conn.close() ;
}
catch(Exception e)
{}
%>
<%
// 跳转
if(flag)
{
// 用户合法
%>
<jsp:forward page="login_success.jsp"/>
<%
}
else
{
// 用户非法
%>
<jsp:forward page="login.jsp"/>
<%
}
%>
</center>
</body>
</html>
为什么无论id和password对不对都转向login.jsp