Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to get queryParameter from Request?

 
ammu lu
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,

I have a small doubt regarding query string, i am getting the query parameter from the request, but for some special characters i am not able to get any String . for ex:%,&,+,\ etc., To get correct String for these character from the request what i need to do?
can you please help on this? Thanks in advance.....
 
Ashika Sharma
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use the java.net.URLEncoder class to encode all of your parameter values.
 
James Ellis
Ranch Hand
Posts: 205
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Expanding on that..if the request came to you via a GET or POST, it should already be encoded.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65111
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by James Ellis:
Expanding on that..if the request came to you via a GET or POST, it should already be encoded.
Not necessarily.

If the data was from a form submission, then yes, the data is automatically encoded.

However, if a link with parameters was built in code (either client or server side), then the data needs to be properly encoded.

That also applies to Ajax requests.
 
zeba saj
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If it is get method we can use encodeURIComponent("field name") in
java script
 
Amit Ghorpade
Bartender
Posts: 2854
10
Fedora Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi small wonder welcome to Javaranch,
Your display name does not follow the Javaranch Naming policy.

Please change it here.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65111
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Dilshad", please check your private messages for an important administrative matter.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic