Servlet Interview Questions and Answers, job interview questions, interview questions, Servlet interview faqs!
Sycorax - complete tutorials
Programming Tutorials
" Java provides the industry - software companies and customer alike , an opportunity to create a true open computing environment where software is portable,
and customers benefit from increase competition. "
Java and the Future
December 1, 2008-LEJB 3.1: EJB New and Improved!
The EJB 3.0 specification was a huge improvement from what you were used to in the early versions of EJB. Available as an early draft, EJB 3.1 has many more features and is even easier to use.
December 1, 2008-Should Java Assert that Network I/O Can't Occur on the UI Thread?
Doing network I/O on the user interface (UI) thread is bad. Most developers know that and can tell you why; unfortunately, it's still done.
Register now to recieve special alert and latest technology news!
Java Servlet Interview Questions
What is Request Headers?
When an HTTP client (e.g. a browser) sends a request, it is required to supply a request line (usually GET or POST). If it wants to, it can also send a number of headers, all of which are optional except for Content-Length, which is required only for POST requests.
Give some example of Request Headers?
- Accept The MIME types the browser prefers.
- Accept-Charset The character set the browser expects.
- Accept-Language The language the browser is expecting, in case the server has versions in more than one language.
- Authorization Authorization info, usually in response to a WWW-Authenticate header from the server.
- Content-Length (for POST messages, how much data is attached)
- Cookie (one of the most important headers; see separate section in this tutorial on handling cookies)
- Host (host and port as listed in the original URL)
- If-Modified-Since (only return documents newer than this, otherwise send a 304 "Not Modified" response)
- Referer (the URL of the page containing the link the user followed to get to current page)
- User-Agent (type of browser, useful if servlet is returning browser-specific content)
How to read Request Headers from servlet?
just call the getHeader method of the HttpServletRequest, which returns a String if the header was supplied on this request, null otherwise. Rather than looking up one particular header, you can use the getHeaderNames to get an Enumeration of all header names received on this particular request.
Enumeration headerNames = request.getHeaderNames();
while(headerNames.hasMoreElements()) {
String headerName = (String)headerNames.nextElement();
out.println("<TR><TD>" + headerName);
out.println(" <TD>" + request.getHeader(headerName));
}

