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 Doubts regarding request and response objects. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Doubts regarding request and response objects." Watch "Doubts regarding request and response objects." New topic
Author

Doubts regarding request and response objects.

Aashima Arora
Ranch Hand

Joined: Jun 15, 2010
Posts: 59

Hi,
Iam having some confusions..

Iam having these to servlets, what iam doing is to try to include the output of another servlet into my servlet.
FirstServlet : In which the output of SecondServlet is to be included.

FIRST SERVLET





SECOND SERVLET






Doubts:

1. what do the request and response objects contain in the rd.include(request,response); i tried request.toString() and response.toString(). though am sure that request is obviously the GET request for the first servlet but dont know what the response object contains.
2.Iam not able to understand the way we sent request parameters. like " ?myname=aashima",i mean it is the path ,so can we just pass the information as a
query string appended to the destination URL.
3.and am sorry about the weirdest confusion. what does the response.setContentType("text/html") do. i mean in the second servlet when we write
out.println(attribute+ ":" + request.getAttribute(attribute)+"<BR>"); we have no opening tags (out.println("<html">) and likewise no closing tags. so we can use it this way?


i have just started the preparation so my basics are not clear but am trying. would be great if you guys help )

Aashima Arora
Ranch Hand

Joined: Jun 15, 2010
Posts: 59

please help (
Swastik Dey
Rancher

Joined: Jan 08, 2009
Posts: 1477
    
    6

Response object contains the response headers, and few of them are as follows
Body,Bytes received,Content Length,Http version,Response code

response.setContentType("text/html");

By using the above you are setting the content type of the response body, i.e. how the browser will interpret the content. So in this case the text will be interpreted as html. If you change this to text/plain, the browser will show it as plain text.

For e.g. if you set the content type to text/html the following <b>hello</b> will appear in browser as bold hello. But if you set it to text/plain the browser will show it as <b>hello</b>

Correct me if I am wrong.

Swastik
Aashima Arora
Ranch Hand

Joined: Jun 15, 2010
Posts: 59

yeah, you are right. basically i was concerned with the response object wrt the include method i.e what are we doing with rd.include(request,response).i know we are trying to inculcate the response of the second servlet in the first servlet. so how does this method work ?
Swastik Dey
Rancher

Joined: Jan 08, 2009
Posts: 1477
    
    6

As far as my knowledge goes, request and response headers are passed to the included serlvet. The included servlet generates its contents that is to be rendered, and that is included with the first servlet to produce the final output.
Aashima Arora
Ranch Hand

Joined: Jun 15, 2010
Posts: 59

Alright ! I got it Thank you very much
Aashima Arora
Ranch Hand

Joined: Jun 15, 2010
Posts: 59

One more query , when i set the content type as html , i dont need to open any body tags , just the <title>tag to set the title if at all ?
Swastik Dey
Rancher

Joined: Jan 08, 2009
Posts: 1477
    
    6

Not exactly. Setting the content type has got no relation with ending or closing tags. Unlike XML, html is not error prone to tags. Even if you write a html page without any tags that also will be interpreted without any errors.
Aashima Arora
Ranch Hand

Joined: Jun 15, 2010
Posts: 59

oh alright... i understand a bit i will need to do some more coding before i actually understand everything
thank you so much
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Doubts regarding request and response objects.