This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
The moose likes Servlets and the fly likes HTTP POST - URL Encoding Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "HTTP POST - URL Encoding" Watch "HTTP POST - URL Encoding" New topic

HTTP POST - URL Encoding


Joined: Jan 02, 2002
Posts: 25
I read somewhere that for HTTP POST method, we don't have to do URL encoding because Browser (or ?) will do the automatic encoding before sending the form data. Is it true? Whether all browsers supports this feature.
Thanks in advance.
dibs dibley

Joined: Aug 31, 2003
Posts: 13
I'm not sure it is the same for all of them but..
My browser's handling of form encoding is seriously crap.When you submit the form data,it is automatically defaulted to iso-8859-1.
So when I collect the submitted form data in my jsp/servlet I have to do this...
String temp=mybean.getDns1();
temp=new String (mybean.getBytes("ISO-8859-1"),"shift_jis");
Hope this helps!
Jason Davies

Joined: Sep 18, 2003
Posts: 14
I'm not sure exactly what you're asking, but "application/x-www-form-urlencoded" is the default encoding for all forms. See here:
All you need to do in the servlet is retrieve the parameters using HttpServletRequest.getParameter(), for POST or GET requests.
If you want to upload files, then you need to use a different encoding for the form. Without more detail in the question I can't say much more!

<a href="" target="_blank" rel="nofollow"></a> - Web programming articles and tutorials.

Joined: Jan 02, 2002
Posts: 25
In the form, I am having encoded hidden parameter:
<FORM name="testfrm" method="POST">
<input type="hidden" name="hiddenParam" value="">
When my servlet receives the POST request, getParamter still returns the encoded value only instead of decoded value.
String value = request.getParameter("hiddenParam");
I am still getting value as "" instead of ""
Thanks in advance.
Lasse Koskela

Joined: Jan 23, 2002
Posts: 11962
You're using URL encoding (the percentage stuff) where you should be using HTML entity "&#64;".

Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
I agree. Here's the link:
subject: HTTP POST - URL Encoding
It's not a secret anymore!