Servlets or JSP
Servlets can be used to perform complex business diagnostics, route data data between screens, and generate HTML response. But with the introduction of JSP most of these tasks are easily executed without using servlet technology. Keeping the essence of JSP in mind, a developer should use features such as useBean and custom tags to simplify the complex tasks.
The criterion that provides a base to choose between servlets and JSP is the best understood by understand the Web component model. The web components of an application can be categorized into two groups, the presentation component and the front component. The presentation component is used for designing the HTML response interface while the front component is used to perform subsidiary tasks such as handling HTTP requests. The front component is not responsible for the presentation but provides an access point for the application.
Consider a very common e-commerce application in the form of an online shopping site. A modular design for the application can be drawn up by using JSP technology. This facilitates segregation of static and dynamic content and division of work that is role specific. HTML proficient designers can develop the presentation content and Java professionals can simultaneously develop the business diagnostics. In other words, the repetitive data manipulation can be encapsulated in a Java-Bean component and displayed repeatedly by using an HTML format.
Although JSP clearly defines the work profiles of a web web designer and a web developer or programmer, facilitating easy application development, there are some instances that require explicit use of servlets.
They are:
1. Dynamic generation of binary data: These can be in the form of images such as a graphical summary for the stock performance of an organisation. The image in this case needs to be updated constantly against the stock status in the database. The execution for constant update.
2. File Type format support to extent web servers functionality: To add support for a new file format, a servlet can easily be mapped to the JSP files. As a result, files with JSP extension are parsed and compiled to generate the response that is sent back to the browser.
Therefore, the choice between servlets and JSP, in a nutshell, will differ according to the client requirement, structure of the development team, and the time allocated for applications in their own way.
Servlets are tools that can be used to create low-level applications that do not require regular alterations or modifications.
JSP on the other hand, is a presentation centric application development tool that can be used to handle both static and dynamic contents of a web application.
|