wood burning stoves*
The moose likes Servlets and the fly likes how to request a hidden field value on servlet with post method? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "how to request a hidden field value on servlet with post method?" Watch "how to request a hidden field value on servlet with post method?" New topic
Author

how to request a hidden field value on servlet with post method?

moshik salem
Greenhorn

Joined: Dec 06, 2011
Posts: 10
hi,

i am trying to get a hiddenField value on servlet but i am getting a null value, how to solve this?

my jsp code look like this:

<form action="ImageResizeServlet" method="post">
<input type="hidden" id="pageWidth" name="pWidth"></input>
</form>

and my servlet code look like this:

protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
try {
String s=request.getParameter("pWidth");
....

what to do?
thank you.
duy nguyen H
Greenhorn

Joined: Aug 30, 2011
Posts: 11
Guess you need to initialize value for this field. Either by default value by yourself or computed value before sending it to server for further processing.
moshik salem
Greenhorn

Joined: Dec 06, 2011
Posts: 10
i have already intalized the value of the hiddenField with javaScript before submitting it to the servlet, but still i am getting null value.

any other idea?
Vinoth Thirunavukarasu
Ranch Hand

Joined: Dec 18, 2008
Posts: 164

By Just with the below code how you can submit the form


Just add one submit button in the above form and check it
moshik salem
Greenhorn

Joined: Dec 06, 2011
Posts: 10
thank you, when i use the submit button it works. but i want that the form will submit himself without any user interaction.

so can someone tell me how to post a form to the servlet with no button pressing or any other event?

i tried in my javaScript to do: form.submit();

but the parameters on servlet are null when i do that.

any idea?
duy nguyen H
Greenhorn

Joined: Aug 30, 2011
Posts: 11
Could you post javascript snippet onto the site for reviewing? No difference between click on submit button or call form.submit() from javascript code.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to request a hidden field value on servlet with post method?
 
Similar Threads
JSP to servlet
Arrays in JSP form
sendRedirect fails to post data along with url if the data is too large
request.getParameter() returns a null value in the servlet
HTTP POST - URL Encoding