Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

FAQ's on Java Servlets

  1. What mechanisms are used by a Servlet Container to maintain session information?

Cookies, URL rewriting, and HTTPS protocol information are used to maintain session information

  1. Difference between GET and POST

In GET, your entire form submission can be encapsulated in one URL, like a hyperlink. Query length is limited to 260 characters, not secure, faster, quick and easy.

In POST, your name/value pairs inside the body of the HTTP request, which makes for a cleaner URL and imposes no size limitations on the form's output. It is used to send a chunk of data to the server to be processed, more versatile, most secure.

  1. What is session?

The session is an object used by a servlet to track a user's interaction with a Web application across multiple HTTP requests.

  1. What is servlet mapping?

The servlet mapping defines an association between a URL pattern and a servlet. The mapping is used to map requests to Servlets.

  1. What is servlet context?

The servlet context is an object that contains a servlet's view of the Web application within which the servlet is running. Using the context, a servlet can log events, obtain URL references to resources, and set and store attributes that other servlets in the context can use.

6.Which interface must be implemented by all servlets?

Servlet interface.

  1. What information that the ServletRequest interface allows the servlet access to?

Information such as the names of the parameters passed in by the client, the protocol (scheme) being used by the client, and the names of the remote host that made the request and the server that received it. The input stream, ServletInputStream.Servlets use the input stream to get data from clients that use application protocols such as the HTTP POST and PUT methods.

  1. What information that the ServletResponse interface gives the servlet methods for replying to the client?

It allows the servlet to set the content length and MIME type of the reply. Provides an output stream, ServletOutputStream and a Writer through which the servlet can send the reply data.

  1. When using servlets to build the HTML, you build a DOCTYPE line, why do you do that?

I know all major browsers ignore it even though the HTML 3.2 and 4.0 specifications require it. But building a DOCTYPE line tells HTML validators which version of HTML you are using so they know which specification to check your document against. These validators are valuable debugging services, helping you catch HTML syntax errors.

http://validator.w3.org and 
http://www.htmlhelp.com/tools/validator/ are two major online validators.

10. What's the advantages using servlets than using CGI?

Servlets provide a way to generate dynamic documents that is both easier to write and faster to run. It is efficient, convenient, powerful, portable, secure and inexpensive. Servlets also address the problem of doing server-side programming with platform-specific APIs: they are developed with Java Servlet API, a standard Java extension.

11.Which code line must be set before any of the lines that use the PrintWriter?

setContentType () method must be set before transmitting the actual document.



This post first appeared on Web Applications Development | Custom Web Applicat, please read the originial post: here

Share the post

FAQ's on Java Servlets

×

Subscribe to Web Applications Development | Custom Web Applicat

Get updates delivered right to your inbox!

Thank you for your subscription

×