Reputation: 127
I have a little bug that I hope someone can solve for me.
servlet1:
The story here is simple - I created a form and inside it an image. When you click this image information should be submitted to servlet2.
public void f1(HttpServletRequest request, HttpServletResponse response) throws
IOException
{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.print("<html></br>");
out.print("<script language='javascript' type='text/javascript'
src='functions.js'></script></br>");
out.print("<body></br>");
out.print("<form method='post' name='mainForm' action='servlet2'><br/>");
out.print("<img id='someId' src='someSrc' onclick='submit()'/><br/>");
out.print("<label id='gameStatus'>Welcome!</label></br>");
out.print("</form></br>");
out.print("</body>\n</html></br>");
}
OK, I clicked the image and information is now submitted (I suppose)
servlet2:
Here I would just like to print out the parameters submitted earlier.
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
Enumeration parameters = request.getParameterNames();
while (parameters.hasMoreElements())
{
out.print((String)parameters.nextElement() + "<br/>");
}
}
unf. my output is null so i guess information was not submitted. The question is why? any typos? or a logical prob? Thank you!
Upvotes: 0
Views: 908
Reputation: 17269
What information you are trying to pass? I don't see any input field in your form.
Kindly try to add input in your form. Let us see if it is displayed in your second servlet.
out.print("<form method='post' name='mainForm' action='servlet2'><br/>");
out.print("<input type='text' name='param1' value='test' /><br/>");
out.print("<img id='someId' src='someSrc' onclick='submit()'/><br/>");
out.print("<label id='gameStatus'>Welcome!</label></br>");
Check if param1 is displayed.
Upvotes: 1