aspose file tools*
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 Spring in Action this week in the Spring 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: how to request a hidden field value on servlet with post method?