If the parameter information sent to a
servlet as encoded POST data has been read manually using the Reader or InputStream obtained using the getReader() or getInputStream() method of the ServletRequest, then, it cannot be read again.
This will be displayed!
value obtained manually = value1=750&value2=1000&AddButton=Submit+Query
value obtained again manually is = null
val1 obtained again is = null
val2 obtained again is = null
Now consider the following code:
public class PostTest extends HttpServlet
{
public void doPost(HttpServletRequest req, HttpServletResponse res) throws SE, IOE
{
res.setContentType("text/plain");
PrintWriter out = res.getWriter();
out.println("val1 obtained is = "+req.getParameter("value1"));
out.println("val2 obtained is = "+req.getParameter("value2"));
out.println("val1 obtained again is = "+req.getParameter("value1"));
out.println("val2 obtained again is = "+req.getParameter("value2"));
}
}
Now if the form (in your example) PostTest.html is accessed in a browser, and the values entered are value1 = 750 and value2 = 1000 and you submit the form.
This will be displayed:
val1 obtained is = 750
val2 obtained is = 1000
val1 obtained again is = 750
val2 obtained again is = 1000
Here the "String HttpServletRequest.getParameter(String )" method has been implemented in such a way that no matter how many times it is called for a particular parameter, it always returns the parameter value.
[ June 10, 2003: Message edited by: Amer Khan ]