我有个例外,我不知道为什么。它说它的a数字格式异常为空。我看过其他关于这个的帖子,但是没有一篇能解决我的问题。我的profile类是一个简单的类,它有id username lastname age和favTeam以及setters、getter和构造函数。有人知道为什么会这样吗?
public ProfileServlet() {
super();
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
HashMap team = new HashMap();
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
response.setContentType("application/json; charset=UTF-8");
//String requestUrl = request.getRequestURI();
PrintWriter out = response.getWriter();
Profile test = new Profile();
int id;
test = team.get(id = Integer.parseInt(request.getParameter("ID")));
if(test != null)
{
out.println("ID: " + test.getId());
out.println("name: " + test.getUsername());
out.println("lastname: " + test.getLastname());
out.println("age: " + test.getAge());
out.println("favTeam: " + test.getFavTeam());
}
else
{
//ERROR
}
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
String id = request.getParameter("id");
String age = request.getParameter("id");
int x = 0;
if(id!=null){
try{
x = Integer.parseInt(id);
}catch(Exception e){
}
}
String username = request.getParameter("username");
String lastname = request.getParameter("lastname");
String favTeam = request.getParameter("favTeam");
int numage = 0;
if(id!=null){
try{
numage = Integer.parseInt(age);
}catch(Exception e){
}
}
Profile profile = new Profile(x,username,lastname,favTeam,numage);
team.put(profile.getId(),profile);
}
}
我的.xml
Homework
ProfileServlet
ntrut.ProfileServlet
ProfileServlet
/profile