• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

conditions to get Http parameters

 
faiza haris
Ranch Hand
Posts: 173
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Plz throw light on this frm the Servlet spec pg 32
the condition to be met before post form data will be populated to parameter set:
3. the content type is application/x-www-form-urlencoded
i couldnt understand this point.
can anyone explain by any code example.
thanx
f
 
Tom Arons
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Faiza,
You can check the content type of the data sent via the input stream by method ServletRequest.getContentType(). The type "application/x-www-form-urlencoded" is a content type of the input stream, and if it is of this type, the data can then be retrieved with the getParameter() method.
 
faiza haris
Ranch Hand
Posts: 173
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanx tom!
an example of content could be text/html and wht confuses me is that content type is
"application/x-www-form data"
is that the path?
sorry for bothering.........
f
 
Tom Arons
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For the ServletResponse setContentType() method the content type may include the type of character encoding used, for example, text/html; charset=ISO-8859-4. This is taken from the servlet API docs. This is where you are thinking of the MIME type such as "text/html", "text/plain", or "image/gif",....
So it seems even though ServletRequest.getContentType() gets the MIME type of the input stream, it retrieves the additional information that we are talking about. You can probably think of it as header information I guess.
 
faiza haris
Ranch Hand
Posts: 173
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So heres wht i understood
For ServletRequest:
getContentType()-returns mime type of the request body
For HttpServletRequest
We can get the parameters if the content type is application/urlencoded query string ??So it is the query string which is url encoded???errr...help! ??
For ServletResponse:
setContentType(type)- set the content type of response sent to client which is xter encoding e.g text/html etc
 
Chintan Rajyaguru
Ranch Hand
Posts: 341
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Faiza,
Here is the thing:
When you submit an HTML form the data goes to the server. In order for HttpServletRequest object to understand, what that data is, it should be in certain known format otherwise it will be a English-French problem.
Now, HttpServletRequest object can interpret data only if it is in application/x-www-form-urlencoded format. If the incoming form data is in this format, HttpServletRequest interprets the data and hence you can call methods such as getParameter () to retrieve the data.
Why application/x-www-form-urlencoded format? because it is HTML standard. If you go to http://www.w3.org/MarkUp/html-spec/html-spec_8.html
and scroll down about 3/4 of the page, you will find the following sentence
"The default encoding for all forms is `application/x-www-form-urlencoded'"
page 32 of the servlet spec says that incoming data should confirm with HTML specs.
All this has nithing to do with response. For response you have contentTypes such as text/plain, text/html etc available.
Hope this helps
Chintan
 
faiza haris
Ranch Hand
Posts: 173
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All clear!
thanx chintan...the link is very informative too...i was confusing the basics.....
grateful for the help....
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic