Database Reference
In-Depth Information
JSP is compiled, whereas scripts are interpreted. JSP utilizes the Java Servlet technology to achieve
server-side processing.
A JSP consists of Java code embedded within a structured document such as HTML or XML.
The basic idea is to use the markup language for the static portion of the presentation and embed
special tags within the page to mark up the dynamic content. The tags are used to process incom-
ing requests from a client and consequently generate a response. As JSP uses additional system
resources, wherever the presentation content is static, a plain HTML page should be used. The Use
of JSP allows the presentation code to be easily maintained as regular HTML code and shields the
Web developer from having to deal with unfamiliar language and tools.
Java Scriptlets can be embedded in a JSP file, though their usage should be kept to the mini-
mum. Sun recommends the use of JSP where there is a significant amount of dynamic content
that is envisaged.
11.2.3.4.1.2 Ser vlet s — Servlets are primarily used as a conduit for passing data back and
forth between a Web client and an enterprise application running on a server. Servlets are server-
side programs that execute in a servlet engine, which often forms a part of the HTTP server, but
may also run stand-alone. Servlets run inside the servlet engine or container hosted on a Web
server; the servlet container manages the life cycle of a servlet and translates the Web client's
requests into object-based requests and, in reverse, the object-based responses back to the Web
client via HTTP.
Servlets provide a more effective alternate mechanism to the traditional CGI scripts for inter-
action between the server-based business logic and the Web-based clients. Servlets are usually
employed to handle preliminary tasks like gathering and checking for valid inputs from the entry
fields of a Web page. Once the basic checks are completed, the data are then passed on to more
suitable component(s) for actual processing.
JSP specification provides the JSP with the same capabilities as the servlet. The basic
idea is to leverage JSP for presentation-centric tasks and utilize the servlets for busi-
ness logic processing-centric tasks. Servlets are preferred for more logical tasks as they
are also comparatively easier to debug. Since Java code is embedded within the JSP, it
may seem that the separation of presentation from business logic is not realistic. JSP should
primarily be focused on presentation, and any Java code embedded within the JSP should
primarily be for communication with servlets, other control or data entities, and so on.
JSP development usually adopts the Model 2 architecture based on the Model-View-
Controller (MVC) architecture discussed earlier. It uses one or more servlets as control-
lers; requests received by frontline servlet(s) are redirected to the concerned JSPs. Usually,
JavaBeans is used as the model that acts as the conduit to pass information between the
controller servlet(s) and the JSPs. The controller fills in the JavaBean based on the request,
and the JSP in turn composes the actual page using values from the JavaBean.
11.2.3.4.1.3 Enterprise JavaBeans (EJB) — EJB components encapsulate business logic. EJB
defines a comprehensive component model for building scalable, distributed server-based enter-
prise Java application component.
 
Search WWH ::




Custom Search