java.lang.NumberFormatException: For input string: "" 是什么意思? 5
java.lang.NumberFormatException:Forinputstring:""java.lang.NumberFormatException.forI...
java.lang.NumberFormatException: For input string: "" java.lang.NumberFormatException.forInputString(NumberFormatException.java:48) java.lang.Integer.parseInt(Integer.java:468) java.lang.Integer.parseInt(Integer.java:497) com.bdqn.zen.servlet.UserAdd.doPost(UserAdd.java:71) javax.servlet.http.HttpServlet.service(HttpServlet.java:637) javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
UserAdd.java中的部分代码
public class UserAdd extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("utf-8");
String userId=request.getParameter("userId");
String name=request.getParameter("username");
String pass1=request.getParameter("password");
String pass2=request.getParameter("password");
String sex=request.getParameter("sex");
String age=request.getParameter("age");
String tel=request.getParameter("mobile");
String address=request.getParameter("address");
String auth=request.getParameter("auth");
AccountInfo account=new AccountInfo();
account.setUser_id(Integer.parseInt(userId));
account.setUser_name(name);
account.setUser_password(pass1);
account.setUser_gender(sex);
account.setUser_age(age);
account.setUser_tel(tel);
account.setUser_address(address);
account.setUser_role_id(Integer.parseInt(auth));
AccountDao dao=new AccountDao();
int relult=dao.AddAccount(account);
if(relult>0){
response.sendRedirect("ShowAccount");
}else{
response.sendRedirect("userAdd.jsp");
}
}
} 展开
UserAdd.java中的部分代码
public class UserAdd extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("utf-8");
String userId=request.getParameter("userId");
String name=request.getParameter("username");
String pass1=request.getParameter("password");
String pass2=request.getParameter("password");
String sex=request.getParameter("sex");
String age=request.getParameter("age");
String tel=request.getParameter("mobile");
String address=request.getParameter("address");
String auth=request.getParameter("auth");
AccountInfo account=new AccountInfo();
account.setUser_id(Integer.parseInt(userId));
account.setUser_name(name);
account.setUser_password(pass1);
account.setUser_gender(sex);
account.setUser_age(age);
account.setUser_tel(tel);
account.setUser_address(address);
account.setUser_role_id(Integer.parseInt(auth));
AccountDao dao=new AccountDao();
int relult=dao.AddAccount(account);
if(relult>0){
response.sendRedirect("ShowAccount");
}else{
response.sendRedirect("userAdd.jsp");
}
}
} 展开
1个回答
展开全部
account.setUser_role_id(Integer.parseInt(auth));
这句代码,如果获取的参数
String auth=request.getParameter("auth");
auth在前台并没有输入值,就会传入“”,这就是你的错误所在,所以你应该这样做
if(auth!=null&&auth.equals(""))
{
account.setUser_role_id(Integer.parseInt(auth));
}
当然即使这样,如果输入的数字格式错误,也是会抛出异常的。
这句代码,如果获取的参数
String auth=request.getParameter("auth");
auth在前台并没有输入值,就会传入“”,这就是你的错误所在,所以你应该这样做
if(auth!=null&&auth.equals(""))
{
account.setUser_role_id(Integer.parseInt(auth));
}
当然即使这样,如果输入的数字格式错误,也是会抛出异常的。
追问
上面说的com.bdqn.zen.servlet.UserAdd.doPost(UserAdd.java:71)在这是account.setUser_id(Integer.parseInt(userId));
追答
是的,如果没有其他问题,应该就是这一行的异常。
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询