I've developed an html page that sends information to a servlet. In the servlet, I was using the method service to get that information and perform operations.
I've read that other methods that I could use are doGet and doPost. Should I use these methods or is it ok to use the service method?
Another question is about how to use the doPost method. In the servlet I'm using the following piece of code to retrieve information:
for ( Enumeration e = req.getParameterNames(); e.hasMoreElements();) { String param = (String) e.nextElement(); String value = req.getParameter(param); if(param.compareTo("realname") == 0) { id = value; } else if(param.compareTo("mypassword") == 0) { password = value; }}id = req.getParameter("realname");password = req.getParameter("mypassword");
This code is used in :
public void doPost(HttpServletRequest req, HttpServletResponse res)throws ServletException, IOException { ....}
The method doGet looks like:
public void doGet(HttpServletRequest req, HttpServletResponse res)throws ServletException, IOException { doPost(req, res);}
When I use the method get (in the html code) I'm able to get these parameters in the servlet, however, when I use the methos post I can see that there are no iterations in the 'for' loop and the values of id and password are set to null. Does anybody know why?
Update: the html page code that calls the Servlet is:
<form action="identification" method="post" enctype="multipart/form-data"> User Name: <input type="text" name="realname"> Password: <input type="password" name="mypassword"><input type="submit" value="Identification"></form>