• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
moshik salem
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 164
Android Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could you post javascript snippet onto the site for reviewing? No difference between click on submit button or call form.submit() from javascript code.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic