java.lang.NumberFormatException: null异常
这是UsersUpdateServlet的代码 @WebServlet("/updateusers") public class UsersUpdateServlet extends HttpServlet{ UsersDAO usersDAO = new UsersDAO(); @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { this.doPost(req,resp); } @Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { //获取用户需要更新的数据 String id = req.getParameter("id"); String nickname = req.getParameter("nickname"); String age = req.getParameter("age"); String gender = req.getParameter("gender"); String phone = req.getParameter("phone"); String email = req.getParameter("email"); String remark = req.getParameter("remark"); //创建用户对象 Users user = new Users(Integer.parseInt(id),nickname,Integer.parseInt(age),gender,phone,email,new Date(),remark); //提交更新的数据 usersDAO.updateUsers(user); =======这是页面报错的第33行======= //查看更新后的用户信息 resp.sendRedirect("/detail?id="+user.getId()); } }
这是Users代码 package com.imooc.entity; import java.util.Date; public class Users { private Integer id; //用户编号 // private String username; //登录账号 private String name; //登录账号 private String userpass; //登录密码 private String nickname; //用户昵称 private Integer age; //用户年龄 private String gender; //用户性别 private String phone; //联系方式 private String email; //用户邮箱 private Date createTime; //创建时间 private Date updateTime; //账号最后修改时间 private Date lastLogin; //用户最后登录时间 private Integer userStatus; //用户账号状态 0 正常 1 锁定 2 删除 private String remark; //用户备注信息 public Users() { } public Users(String name, String userpass, String nickname, Integer age, String gender, String phone, String email, Date createTime, Date updateTime, Date lastLogin, Integer userStatus) { this.name = name; this.userpass = userpass; this.nickname = nickname; this.age = age; this.gender = gender; this.phone = phone; this.email = email; this.createTime = createTime; this.updateTime = updateTime; this.lastLogin = lastLogin; this.userStatus = userStatus; } public Users(Integer id, String nickname, Integer age, String gender, String phone, String email, Date updateTime, String remark) { this.id = id; this.nickname = nickname; this.age = age; this.gender = gender; this.phone = phone; this.email = email; this.updateTime = updateTime; this.remark = remark; } public Users(Integer id) { this.id = id; } public Integer getId() { return id; } public void setId(Integer id) { this.id = id; } // public String getUsername() { // return username; // } // // public void setUsername(String username) { // this.username = username; // } public String getUserpass() { return userpass; } public void setUserpass(String userpass) { this.userpass = userpass; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getNickname() { return nickname; } public void setNickname(String nickname) { this.nickname = nickname; } public Integer getAge() { return age; } public void setAge(Integer age) { this.age = age; } public String getGender() { return gender; } public void setGender(String gender) { this.gender = gender; } public String getPhone() { return phone; } public void setPhone(String phone) { this.phone = phone; } public String getEmail() { return email; } public void setEmail(String email) { this.email = email; } public Date getCreateTime() { return createTime; } public void setCreateTime(Date createTime) { this.createTime = createTime; } public Date getUpdateTime() { return updateTime; } public void setUpdateTime(Date updateTime) { this.updateTime = updateTime; } public Date getLastLogin() { return lastLogin; } public void setLastLogin(Date lastLogin) { this.lastLogin = lastLogin; } public Integer getUserStatus() { return userStatus; } public void setUserStatus(Integer userStatus) { this.userStatus = userStatus; } public String getRemark() { return remark; } public void setRemark(String remark) { this.remark = remark; } }
13
收起
正在回答
2回答
你代码的这两处都是将字符串转换为整型,你打印输出id和age的值,看看哪个是null
另外,代码中重定向到detail?id=,而从你后来贴出的url看,却是updateusers,你要检查一下这个updateusers是在哪里写的
祝学习愉快!
Java数据库开发与实战应用2018版
- 参与学习 人
- 提交作业 277 份
- 解答问题 4297 个
Java数据库开发的必备技能,从流行的MySQL数据库开始,到Java原生的数据库管理接口JDBC的使用,再到常用的数据持久化框架MyBatis,让你向Java工程师的目标又迈进了一步!
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星