aspose file tools*
The moose likes Servlets and the fly likes How do I change Parameter in servlet? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "How do I change Parameter in servlet?" Watch "How do I change Parameter in servlet?" New topic
Author

How do I change Parameter in servlet?

K Song
Greenhorn

Joined: Aug 19, 2002
Posts: 2
I have a question for any Servlet experts.
getParameter("fieldName") gets the value of the fieldName input from the form.
How can I change fieldName Parameter to new value, and return to the same jsp form.
ex.
1. <input type=text name=fieldName value="hello">
2. when submitted, will execute a servlet that changes fieldName to new value ("You again"). This servlet does not create any HTML. It will forward to pervious form. the previous form (JSP) will display the new value.
3. returns to the same form, but displays the new value.


ks
X Luo
Greenhorn

Joined: Aug 19, 2002
Posts: 5
1. If the getParameter("fieldName")is not null, you then redirect back to the same jsp page with a parameter named, for example, "resetFieldName" and value as "You Again".
2.In jsp page, you need to put extra code to get "resetFieldName" parameter, and then judge the value of that parameter, if the value is null, display <input type=text name=fieldName value="hello">,else display the value acquired from that parameter.
I think you can use getAttribute ("resetFieldName"), then cast it into String for "resetFieldName" parameter. I have not touched Servlet for ages, so I could be wrong. But it worths trying.
Hope that helps.
Good luck.
Dave Vick
Ranch Hand

Joined: May 10, 2001
Posts: 3244
Kick
Welcome to the Java Ranch, we hope you�ll enjoy visiting as a regular however,
your name is not in keeping with our naming policy here at the ranch. Please change your display name to an appropriate name as shown in the policy.
Thanks again and we hope to see you around the ranch!!
As for your question: as far as I know you can't change a RequestParameter once it has been sent to the container. The only thing you could do would be to set a Session variable or a RequestAttribute.


Dave
K Song
Greenhorn

Joined: Aug 19, 2002
Posts: 2
Thank you for all of your help.
James Carman
Ranch Hand

Joined: Feb 20, 2001
Posts: 580
Or, if you are using the Servlet 2.3 API, you can use a javax.servlet.http.HttpServletRequestWrapper object to "spoof" the value of the parameter.


James Carman, President<br />Carman Consulting, Inc.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How do I change Parameter in servlet?