• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How do I change Parameter in servlet?

 
K Song
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
X Luo
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3244
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
K Song
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for all of your help.
 
James Carman
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic