• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem with Params

 
Prasad Babu
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have one JSP that has some fields, the action method is GET and the action is itself.

Problem I am getting is,

every time I submit the JSP, the params are adding to URL. it is good. But in my case the params are appeded each time not overwriting the existing params. Here is example.

http://localhost/App/index.jsp?name=prasad -- First time
http://localhost/App/index.jsp?name=prasad&name=babu -- second time

its not supposed to be like that as i am getting only single param value.

Any idea?

Thanks in advance.
Prasad
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See:
java.lang.String)" target="_blank" rel="nofollow">http://java.sun.com/j2ee/1.4/docs/api/javax/servlet/ServletRequest.html#getParameterValues(java.lang.String)
 
Prasad Babu
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ben,

Thaks for your reply. I know about what you have mentioned. I want one one parameter value not all. how do we find out the latest one? Here i want to make a note that I want only latest one.

thanks,
Prasad.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you have more than one parameter with the same name the best way to retrieve them is to use getParameterValues. If you want a particular one, iterate through the array and grab the one you want.

If you only want one, why are you sending multiple params with the same name?

Also, the servlet spec specifically warns that there is no guarantee as far as the order of params returned. The last one may not necessarily be the one you want.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic