• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

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

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Rancher
Posts: 377
Android Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Which is deprecated though ...
 
Nikhil Chandran
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
True ...
 
Sean Clark
Rancher
Posts: 377
Android Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic