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.
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 )
Response object contains the response headers, and few of them are as follows
Body,Bytes received,Content Length,Http version,Response code
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>
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 ?
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.
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.