日期:2014-05-17  浏览次数:20834 次

请教高人指点,java.lang.NullPonintException at com.servlet.UserRegServlet.doPost
register.jsp里的html代码:
<body>
  <form action="com/servlet/UserRegServlet" method="post" onsubmit="register()">
  用户名: <input type="text" name="username" /></br>
  密&nbsp;&nbsp;码: <input type="password" name="password"/></br>
  确认密码:<input type="password" name="againpass"/></br>
  性&nbsp;&nbsp;别:<select name="gender"><option value="男">男</option>
  <option value="女">女</option></select> </br>  
   
  密码保护问题<select name="question" >
  <option value="您的真实姓名?" >您的真实姓名?</option>
  <option value="您的高中班主任的名字?" >您的高中班主任的名字?</option>
  <option value="您的手机号码?">您的手机号码?</option>
  </select></br>
  答&nbsp;&nbsp;案:<input type="text" name="answer"/></br>
  <input type="submit" name="submitReg" value="注册"/> 
  "
  </form>
  </body>

UserRegServlet类的代码:
package com.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.dao.UserDao;
import com.entity.Users;
import com.tool.Chinese;
//用户注册验证
public class UserRegServlet extends HttpServlet{
UserDao dao=null;
public void doPost(HttpServletRequest request,HttpServletResponse response)throws ServletException,IOException{
Users user=new Users();
String username = Chinese.chinese(request.getParameter("username")).trim();
String password=request.getParameter("password");
//验证用户输入的用户名是否已经存在
if(dao.selectPassword(username) == null || dao.selectPassword(username).equals("")){
 
  user.setUserName(username);
  user.setUserPwd(Chinese.chinese(request.getParameter("password")).trim());
  user.setGender(request.getParameter("gender"));
  user.setQuestion(Chinese.chinese(request.getParameter("question")).trim());
  user.setAnswer(Chinese.chinese(request.getParameter("answer")).trim());
   
  dao.insertUser(user);
  request.getRequestDispatcher("RegSuccess.jsp").forward(request, response);
  }else{
  request.setAttribute("success", "该会员名称已经存在!!!");
  }
}
public void doGet(HttpServletRequest request,HttpServletResponse response)throws ServletException,IOException{
doPost(request,response);
}

}
web.xml里的代码:
  <servlet>
  <servlet-name>UserRegServlet</servlet-name>
  <servlet-class>com.servlet.UserRegServlet</servlet-class>
  </servlet>
  <servlet-m