This week's book giveaway is in the General Computing forum.
We're giving away four copies of Emmy in the Key of Code and have Aimee Lucido on-line!
See this thread for details.
Win a copy of Emmy in the Key of Code this week in the General Computing forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Paweł Baczyński
  • Piet Souris
  • Vijitha Kumara

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

 
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.
 
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?
 
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.
 
Bartender
Posts: 1845
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you want the form submitted without any user interaction?
Or do you want an HTTP request sent without user interaction?

Submitting the form will send an HTTP request - but there are other ways to do that as well.

You could just make an ajax request to the server and pass along the parameter in the url. Might be cleaner than mucking around with the form
ie send a request to ImageResizeServlet?pWidth=[valueFromJavascript]
 
Yup, yup, yup. Tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!