File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes conditions to get Http parameters Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Professional Certification » Web Component Certification (SCWCD/OCPJWCD)
Reply Bookmark "conditions to get Http parameters" Watch "conditions to get Http parameters" New topic
Author

conditions to get Http parameters

faiza haris
Ranch Hand

Joined: Oct 17, 2000
Posts: 173
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

Joined: Jan 04, 2002
Posts: 10
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

Joined: Oct 17, 2000
Posts: 173
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

Joined: Jan 04, 2002
Posts: 10
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

Joined: Oct 17, 2000
Posts: 173
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

Joined: Aug 19, 2001
Posts: 341
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


ChintanRajyaguru.com
SOADevelopment.com - Coming soon!
faiza haris
Ranch Hand

Joined: Oct 17, 2000
Posts: 173
All clear!
thanx chintan...the link is very informative too...i was confusing the basics.....
grateful for the help....
 
 
subject: conditions to get Http parameters
 
Threads others viewed
how to add values to servlet and call that servlet
Value from select element is null in request
validation.xml NullPointerException
WA #2 ..... word association
Words that differ by one letter
WebSphere development made easy
without the weight of IBM tools
http://www.myeclipseide.com