I made an index page in which you take the value of checkbox and pass it on to a file named AddToWork.java but it is showing null pointer exception. There is some problem in passing the value of the checkbox. Kindly help. Here is the code snipped for index page
<td>
<center>
<form action="addtowork?id2=<%=mail.getTempToken()%>" method="post">
<input type="submit" value="Add to my work">
<input type="checkbox" name="flag" value="flag">High Priority</form>
</center></td>
for AddToWork.java
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
EmailDesc mail = new EmailDesc();
String imp = new String();
imp = (String) request.getParameter("flag");
String thisid = request.getParameter("id2");
Home home = new Home();
User user = new User();
user = (User) request.getSession().getAttribute("user");
mail = home.getEmail(thisid, user);
home.givePermanentToken(mail,thisid);
if (imp.equals("flag")){
System.out.println("Priority Changed to " + mail.getPriority() + "!");
}
response.sendRedirect("index1.jsp");
}
If I remove the if statement in addtowork.java, the code runs perfectly.
Aucun commentaire:
Enregistrer un commentaire