WTAD Solutions 4
45.Briefly discuss the following HTTP 1.1 request headers:
- i) Accept ii) Accept-Charset iii) Host iv) Accept-Language v) Authorization vi) Cookie vii) User-Agent
Ans: there are various httpheader in servlet are as follow.
- Accept Charset
- Accept Language
- User Agent
This header specifies the MIME types that the browser or other clients can handle. A servlet that can return a resource in more than one format can examine the Accept header to decide which format to use. For example, images in PNG format have some compression advantages over those in GIF, but not all browsers support PNG. If you have images in both formats, your servlet can call request.getHeader(“Accept”), check for image/png, and if it finds a match, use blah.png filenames in all the IMG elements it generates. Otherwise, it would just use blah.gif.
This header indicates the character set the browser can use.
This header specifies the client’s preferred languages in case the servlet can produce results in more than one language. The value of the header should be one of the standard language codes such as en, en-us, da, etc.
In HTTP 1.1, browsers and other clients are required to specify this header, which indicates the host and port as given in the original URL. Because of the widespread use of virtual hosting (one computer handling Web sites for multiple domain names), it is quite possible that the server could not otherwise determine this information. This header is not new in HTTP 1.1, but in HTTP 1.0 it was optional, not required.
This header returns cookies to servers that previously sent them to the browser. Never read this header directly because doing so would require cumbersome low-level parsing; use request.getCookies instead
This header is used by clients to identify themselves when accessing password-protected Web pages.
This header identifies the browser or other client making the request and can be used to return different content to different types of browsers. Be wary of this use when dealing only with Web browsers; relying on a hard-coded list of browser versions and associated features can make for unreliable and hard-to-modify servlet code. Whenever possible, use something specific in the HTTP headers instead. For example, instead of trying to remember which browsers support gzip on which platforms, simply check the Accept-Encoding header. However, the User-Agent header is quite useful for distinguishing among different categories of client. For example, Japanese developers might see whether the User-Agent is an Imode cell phone (in which case they would redirect to a chtml page), a Skynet cell phone (in which case they would redirect to a wml page), or a Web browser (in which case they would generate regular HTML).
46.Explain the following methods of HttpServletResponse with examples.
- i) setContentType() ii) setStatus() iii) sendError() iv) sendRedirect() v) setContentLength()
- vi) encodeURL() vii) isCommited(
- It Use the setContentType method of HttpServlet Response for this task.
- The MIME type for JPEG.
- The default behavior of this method is to call setStatus(int sc) on the wrapped response object.
- The 404 status code is used when no document is found on the server.
- The sendError method sends a status code (usually 404) along with
- a short message that is automatically formatted inside an HTML
- document and sent to the client.
- The 302 status code directs the browser to connect to a new locatin.,The sendRedirect
- method generates a 302 response along with aLocation header giving the URL of the new document. Either anabsolute or a relative URL is permitted; the system automatically
- translates relative URLs into absolute ones before putting them in theLocation header
This method setd the content-length header,which is useful the browser support presidents HHTP coonection.
Encodes a URL string. These method overloads can be used to encode the entire URL, including query-string values. To encode or decode values outside of a web application,
thesse method specify or look up a cooment associated with the cookie.with version 0 cookie .the comment is used purely for information purpose on the server it is not sent to the client.
Answer the following:
- Error between 400 and 499 represents ____.
Ans: client error
- If the cookies are disabled on clinet-side, the alternate mechanism that can be used is _____ .
- URL Rewriting b. Forcefully enable the cookies c. Use of beans d. None of the above
Ans:d None of above
- In servlet, _____ method is used with session object to store information in a session.
- CGI Stands for __________.
Ans:Common Gateway Interface
- HTML elements with no content are called _______ elements.
Ans:object oriented language and popular programming language
- Error between 500 and 599 represents ____.
Ans server error
- In HTML, <ol> tag is used to create list items with bullets. (True / False)
In html ol tag is used to create list items with numbers
- We must configure and map all jsp files into web.xml. (True / False)
- What kind of information 400-499 status code provides?
- Error between 100 and 199 represents ____.
Ans :informational error
- What is the use of <load-on-startup> element of web.xml?
Ans: load-on-startup means that the servlet must be loaded and initialized on startup of the webapp (i.e. as soon as it is deployed, without waiting for a request to the servlet). The number indicates the order of the initialisations. If another servlet has 1, it will be loaded before. If another has 3, it will be loaded after.
- The method getWriter returns an object of type PrintWriter. This class has println methods to generate output. Which of these classes define the getWriter method? Select the correct answer. A. HttpServletRequest B. HttpServletResponse C. ServletConfig D. ServletContext