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

关于空指针异常,求助!!!
servlet代码如下:
[code=Java][/package com.experiment.usermanger;

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.experiment.Dao.UserManagerDao;
import com.experiment.Dao.DapImpl.UserManagerDaoImpl;
import com.experiment.vo.UserInfo;

/**
 * 对用户进行管理,调用Dao的增删改查,并对页面进行跳转。
 */
public class UserManagerServlet extends HttpServlet {
private static final long serialVersionUID = 1L;

public UserManagerServlet() {
super();
}

protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {

System.out.println("do get.........");
doPost(request, response);
}

protected void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
request.setCharacterEncoding("UTF-8");
// 增加用户操作
String action = request.getParameter("action");
System.out.println(action);
if ("add".equals(action)) {
addUser(request,response);
}
if ("update".equals(action)){
updateUser(request,response);
}
if ("delete".equals(action)){
deleteUser(request,response);
}
}

private void deleteUser(HttpServletRequest request,
HttpServletResponse response) throws IOException {
System.out.println("删除数据!");
int deleteId = Integer.parseInt(request.getParameter("deleteid"));
UserManagerDao umd = new UserManagerDaoImpl();
umd.deleteById(deleteId);
response.sendRedirect("index.jsp");
}

private String parseBirthday(HttpServletRequest request,
HttpServletResponse response) {
String year = request.getParameter("year");
String month = request.getParameter("month");
String day = request.getParameter("day");
String date = String.valueOf(year + "-" + month + "-" + day);
return date;
}

private void addUser(HttpServletRequest request,
HttpServletResponse response) throws IOException {
System.out.println("提交数据bbb");
// 进行添加操作
UserInfo useradd = new UserInfo();
String userAccount = request.getParameter("userId");
String userName = request.getParameter("nameAll");
String birthday = parseBirthday(request, response);
String sex = request.getParameter("sex");
System.out.println(userAccount+" "+userName+" "+birthday+" "+sex);
int sexnum = 0;
if ("男".equals(sex)) {
sexnum = 0;
} else {
sexnum = 1;
}
useradd.setAccount(userAccount);
useradd.setName(userName);
useradd.setBirthday(birthday);
useradd.setSex(sexnum);
UserManagerDao umd = new UserManagerDaoImpl();
umd.insert(useradd);
System.out.println("存储用户" + userName);
response.sendRedirect("index.jsp");
}

private void updateUser(HttpServletRequest request,
HttpServletResponse response) throws IOException {
System.out.pri