Java Servlet technology and JavaServer Pages (JSP pages) are server-side technologies that have dominated the server-side Java technology market; they’ve become the standard way to develop commercial web applications. Java developers love these technologies for myriad reasons, including: the technologies are fairly easy to learn, and they bring the Write Once, Run Anywhere paradigm to web applications. More importantly, if used effectively by following best practices, servlets and JSP pages help separate presentation from content. Best practices are proven approaches for developing quality, reusable, and easily maintainable servlet- and JSP-based web applications. For instance, embedded Java code (scriptlets) in sections of HTML documents can result in complex applications that are not efficient, and difficult to reuse, enhance, and maintain. Best practices can change all that.
In this article, I’ll present important best practices for servlets and JSP pages; I assume that you have basic working knowledge of both technologies. This article:
- Presents an overview of Java servlets and JavaServer pages (JSP pages)
- Provides hints, tips, and guidelines for working with servlets and JSP pages
- Provides best practices for servlets and JSP pages
Overview of Servlets and JSP Pages
Similar to Common Gateway Interface (CGI) scripts, servlets support a request and response programming model. When a client sends a request to the server, the server sends the request to the servlet. The servlet then constructs a response that the server sends back to the client. Unlike CGI scripts, however, servlets run within the same process as the HTTP server.
When a client request is made, the
service method is called and passed a request and response object. The servlet first determines whether the request is a
POST operation. It then calls one of the following methods:
doGet method is called if the request is
doPost is called if the request is
doPost take request (
HttpServletRequest) and response (
In the simplest terms, then, servlets are Java classes that can generate dynamic HTML content using
To Read More Please Visit Java.Sun.Com