日期:2014-05-20  浏览次数:20977 次

想做个会员登录,怎么运行不出来
在我的另一张帖中有注册的页面:
现在想做个登录的,用了3个jsp文件,如下:
(1)login.jsp
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>用户登录</title>
</head>

<body>
<form id="form1" name="form1" method="post" action="login_deal.jsp">
  用户名:
  <input name="username" type="text" id="username" />
  <br />
  <br />
  密&nbsp;&nbsp;码:
  <input name="pwd" type="text" id="pwd" />
  <br />
  <br />
  <input type="submit" name="Submit" value="提交" />
  <input type="reset" name="Submit2" value="重置" />
</form>
</body>
</html>


(2)login_deal.jsp
<%@ page contentType="text/html; charset=gb2312" language="java" errorPage="" %>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>处理结果</title>
</head>

<body>
<%
request.setCharacterEncoding("gb2312");
String username=request.getParameter("UserID");
String pwd=request.getParameter("UserPWD");
if(!username.equals("") && !pwd.equals("")){
response.sendRedirect("login_ok.jsp");
}else{
response.sendError(500,"请输入登录验证信息");
}
%>
</body>
</html>


(3)login_ok.jsp
<%@ page contentType="text/html; charset=gb2312" language="java" errorPage="" %>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>处理结果</title>
</head>

<body>
登录成功!
</body>
</html>


------解决方案--------------------
String username=request.getParameter("UserID");
String pwd=request.getParameter("UserPWD");
if(!username.equals("") && !pwd.equals("")){

看了这三行代码,我无语了。
首先你的UserID你都没有,你怎么取值?你看看自己的定义<input name="username" type="text" id="username" />
 
其次 (!username.equals("") && !pwd.equals(""))你这样比较就不对。username如果为null,那么你使用这个方法就是抛空指针异常。。。。。
------解决方案--------------------
哈哈 逗死我了 - -
------解决方案--------------------
细心才是王道