This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes JSP and the fly likes Need some help in setting up a url parameter into a form bean Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Need some help in setting up a url parameter into a form bean" Watch "Need some help in setting up a url parameter into a form bean" New topic
Author

Need some help in setting up a url parameter into a form bean

Kuppuraj Gunasekaran
Greenhorn

Joined: Jun 18, 2012
Posts: 10
Hi All,

I am developing a website using JSP. I have a link in a page a.jsp and on click of I pass a couple of parameters to the next page b.jsp.
These parameters I display in b.jsp using jstl requestScope as labels along with few other form fields that take user input.

My problem is when I submit the form, In the servlet that handles the request from b.jsp, I am able to get the form fields. But since these are labels and not form values and are in request scope they are not available in the servlet.

I don't want to put them in session scope. I did try using the <input type="hidden" name="name" value="${requestScope.attributevalue"}/> and tried to retrieve in servlet using request.getParameter("name");

but it did not work. Is there any other way I can retrive it in the Servlet class? or any alternate methods? I tried using <jsp:useBean setProperty> but that was not working either. Am I doing anything wrong?

Please Advice
Greg Charles
Sheriff

Joined: Oct 01, 2001
Posts: 2840
    
  11

Hidden input is the way I would go. Why didn't it work? Can you look at the source of your b.jsp (as rendered) and see if those hidden input fields look correct? Also, make sure they are contained by the form you submit. You could change the submit action from "post" to "get" and easily see the parameters that are being sent to the server. On the other hand, you could use a tool like FireBug (the Net panel) to view the request being sent, whether it's get or post.

Also, "Please advise", not "Please Advice". :)
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60785
    
  65

All modern browsers have built-in debuggers that show network traffic. That should be your first debugging step.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Kuppuraj Gunasekaran
Greenhorn

Joined: Jun 18, 2012
Posts: 10
I did use firebug to debug the request.
I can see the POST request containing the hidden parameter value set but am not sure why the servlet is not able to get it.

This is what am doing
b.jsp



In MyServlet.java



In result.jsp



My problem is I cannot debug the Servlet Code since it is in a remote machine.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60785
    
  65

This is why: enctype="multipart/form-data"

Why did you do this?
Kuppuraj Gunasekaran
Greenhorn

Joined: Jun 18, 2012
Posts: 10
I have a file upload field in that page, and hence I need this.
Is there an alternate way? how is multipart/form-data affecting hidden parameters? Apart from file upload I also have couple of textboxes and radio buttons.
They get processed properly. Only this hidden parameter doesn't get submitted.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60785
    
  65

Kuppuraj Gunasekaran wrote:I have a file upload field in that page, and hence I need this.

There is no file upload in that form.

how is multipart/form-data affecting hidden parameters?

When a multipart form is used, it affects all parameters. They cannot be retrieved with getParameter() and similar methods. You must use the API of the file upload library or parse them yourself.

Apart from file upload I also have couple of textboxes and radio buttons. They get processed properly. Only this hidden parameter doesn't get submitted.

Not buying it. Your description doesn't match your posted code and hidden params will not be treated differently than any other params. You'll need to show us the actual code.
Kuppuraj Gunasekaran
Greenhorn

Joined: Jun 18, 2012
Posts: 10
I am sorry, if I was not clear. I did have file upload stuff in that form. I parse the upload request and check for isFormField or not to process the file type and other form fields. I never thought of getting the input hidden value form that.
But since I need this Id much before processing the file type and other form fields I had tried using getParameter. Din't know that multipart/form-data will affect the input values.

Thanks for the valueble input. Let me try getting the Id while I parse the request and using getFieldName() and get the hidden parameter value by name. Hope it works!!! Thanks again!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Need some help in setting up a url parameter into a form bean
 
Similar Threads
out.print ln dynamic form value picking
Request Scope Question
Beans and Jsps and Servlets
Getting the name of the requesting page
provide interface to the other application