日期:2014-05-18  浏览次数:20719 次

用JSP+tomcat4+SQLserver做一个登陆模块时的问题,急呀,在线等
我的程序包括两个部分
第一部分:login.html
这个部分是没问题的,我给它放在tomcat4的examples/jsp目录下
实现的是界面.
第二部分:verfiylogin.jsp
是用来和数据库实现连接的,源码如下:
<%@   page   language= "java "   contentType= "text/html;   charset=UTF-8 "
pageEncoding= "UTF-8 "%>
<%@   page
import= "com.wxpn.tutorial.db.DB,com.wxpn.tutorial.db.ConnectionPool "%>
<%@   page
import= "java.sql.Connection,java.sql.Statement,java.sql.ResultSet,java.sql.SQLException "%>
<html>
<head>
<meta   http-equiv= "Content-Type "   content= "text/html;   charset=gb2312 ">
<meta   http-equiv= "Content-Language "   content= "zh-cn ">
<title> 登录 </title>
</head>
<body>
<div   align=center> <font   color= "red "> <strong>   <%//获取提交的用户名:
String   strUserName   =   request.getParameter( "txtUserName ");
//获取提交的密码:
String   strPassword   =   request.getParameter( "txtPassword ");
if((strUserName   ==null)||(strUserName.equals( " "))||(strUserName.length()> 20)){
response.sendRedirect( "login.html ");
}
if((strPassword   ==null)||(strPassword.equals( " "))||(strPassword.length()> 20)){
response.sendRedirect( "login.html ");
}
//创建数据库连接对象:
ConnectionPool   connPool   =   DB.getConnPool();
Connection   conn   =   connPool.getConnection();
Statement   stmt   =   null;
ResultSet   rs   =   null;

try   {
int   nextMessageid   =   0;
String   relative_path   =   null;
//sql语句:
String   sql   =   "select   *   from   userInfo   where   username= ' "
+   strUserName   +   " '   and   userpwd= ' "   +   strPassword   +   " ' ";
//创建数据记录集对象:
stmt   =   conn.createStatement();
//执行sql语句,返回一个记录集到rs:
rs   =   stmt.executeQuery(sql);
//如果记录集为非空,表明有相匹配的用户名和密码,登录成功:
if   (rs.next())   {
//登录成功时,把strUserName设成session变量UserName
session.setAttribute( "UserName ",strUserName);
out.println( "登录成功! ");
}   else   {
//否则(记录集为空),表明失败:
out.println( "登录失败! ");
}
}   catch   (SQLException   sqlExc)   {
sqlExc.printStackTrace();
}   catch   (Exception   e)   {
e.printStackTrace();
}   finally   {
//关闭连接,释放数据库资源:
try   {
if   (rs   !=   null)   {
rs.close();
}
if   (stmt   !=   null)   {
stmt.close();
}
connPool.freeConnection(conn);
}   catch   (SQLException   sqlExc)   {
sqlExc.printStackTrace();
}
}
%>   </strong>   </font> </div>
</body>
</html>
问提是当我运行http://lo