This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Servlets and the fly likes how to get queryParameter from Request? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "how to get queryParameter from Request?" Watch "how to get queryParameter from Request?" New topic
Author

how to get queryParameter from Request?

ammu lu
Greenhorn

Joined: Jun 17, 2008
Posts: 3
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

Joined: Feb 17, 2005
Posts: 7
Use the java.net.URLEncoder class to encode all of your parameter values.
James Ellis
Ranch Hand

Joined: Oct 14, 2004
Posts: 205
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

Joined: Jan 10, 2002
Posts: 60749
    
  65

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
zeba saj
Greenhorn

Joined: Jul 17, 2008
Posts: 4
If it is get method we can use encodeURIComponent("field name") in
java script
Amit Ghorpade
Bartender

Joined: Jun 06, 2007
Posts: 2716
    
    6

Hi small wonder welcome to Javaranch,
Your display name does not follow the Javaranch Naming policy.

Please change it here.


SCJP, SCWCD.
|Asking Good Questions|
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60749
    
  65

"Dilshad", please check your private messages for an important administrative matter.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: how to get queryParameter from Request?
 
Similar Threads
Difference between getAttribute and getParameter
can i pass a variable through javascript function to another struts jsp page?
doGet idempotent?
doubt regarding request parameters
Login to ASP page