Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Unable to retrive the proper data from a query string inside jsp page  RSS feed

 
Nikhil Chandran
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello All,
I am trying pass some value through url in the form of query string (like http://url?param1=hello¶m2=real+data) . Please note that the value of param2 contains a '+' character.
My problem is while retrieving the data on other side using request.getParameter(String) method , the value obtained is something like "real data". ie, the + got replaces with a space.
Can any one suggest a possible solution for this problem?

Thanks in Advance
 
Sebastian Janisch
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That is because the + sign is used by the browser to substitute for a space. Hence your servlet strips it out as i thinks it was just a space.

Try real%2Bdata
 
Sean Clark
Rancher
Posts: 377
Android Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey,

Use the core taglib to construct your url - this will encode any parameters which have special characters.

Check out the <c:url> and <c:param> tags.

Sean
 
Nikhil Chandran
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hai
I found that we can encode strings inside a url using the java.net.URLEncoder.encode("real+data","UTF-8").
Now its working fine. Thanks for your help.
 
Sebastian Janisch
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which is deprecated though ...
 
Nikhil Chandran
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sebastian Janisch wrote:Which is deprecated though ...


I think the method URLEncode.encode(String,String) is not deprecated in java1.5
The overloaded method URLEncode.encode(String) is the deprecated one.

Thanks
 
Sebastian Janisch
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
True ...
 
Sean Clark
Rancher
Posts: 377
Android Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Scriptlets just aren't nice to have in JSP's though.

I believe best practise for JSPs is to avoid them unless absolutely necessary (which in this case they are not).

Sean
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!