Understanding JavaServer Pages (JSPs)


The JSP technology is a part of the J2EE standard that addresses the generation and presentation of dynamically generated XML-based content, which is most often HTML or WML content. It is generally focused more on the presentation of HTML than servlets are. The key advantages of JSPs are

  • They offer a clean separation of presentation and business logic, and they encourage the use of the Model-View-Control (MVC) design pattern through the ability to separate the presentation layer of an application from the business layer.

  • They do not require extensive Java programming, simplifying the generation of dynamic content by engineers who are more focused on the HTML presentation than a J2EE developer is. Many JSPs require no Java programming; the author just embeds XML tags into the HTML source code.

JSPs allow the mixing of HTML directives with Java code to generate static and dynamic content easily.

A J2EE server such as WebLogic translates a JSP into a servlet, which then runs in the servlet container. The steps that WebLogic Server performs for a JSP request are

  1. A request for a JSP comes into the server. Commonly the URL portion of the request ends with a .jsp extension. However, the URL could instead be mapped to a JSP in the configuration of the web application.

  2. The server compares the time stamp on an internal cache to see whether the requested JSP file on the file system is newer than the cached version.

    Tip

    WebLogic Server can be configured to not check the JSP file timestamp or to only check it after a certain time period. This is commonly used on production systems where the JSP file will not be changing during runtime. The performance of the server is improved as it does not have to query the file system every time a JSP is requested. This setting is associated with each Web application within the server.

    To change this setting, log into the WebLogic Server console (traditionally at http://<hostname>:7001/console ) and select the Web application you want to change. Select Edit Web Application Deployment Descriptors... at the top of the right pane. If the left pane does not show a control for WebApp Ext, then select the link Configure a New Web App Ext Descriptor... in the right pane. Then go back and select JSP Descriptor under the WebApp Ext control. For the value Page Check Seconds, set the value to "0" (zero) if you want WebLogic Server to check the timestamp on the JSP on every request regardless of how long it has been since the server last checked. If you set this to a positive value greater than zero, then WebLogic Server will check the file system at the interval defined. If you set it to 1 then the WebLogic server will never check the file system.

  3. If there is no cached version of the JSP or if the JSP file is newer than the cached version, the server converts the JSP file into a Java file. This Java file is a type of servlet that contains all the HTML markup and Java code from the JSP file.

  4. The Java file is compiled into a servlet and run in the servlet container just like a normal servlet.

  5. If the JSP file is not newer than the internally cached version, the server runs the servlet. Because the servlet is already compiled and installed, this process is very quick.

That JSPs can be dynamically compiled gives them much of their power. Additionally, because they are based on servlets they have all the power of servlets, including multithreaded concurrent access and database access through JDBC.

Where JSPs and servlets are different is that a JSP is an HTML file first and a Java file second, with only small, if any, amounts of Java code. Servlets, on the other hand, are Java classes first with HTML embedded in them. It is important to understand that any HTML page is already a JSP. You can just rename it with a .jsp extension, and the Web server will automatically convert it to a servlet.

JSPs make application development easier because they are automatically compiled by the Web server. Servlets require a standard development processedit, compile, and install. With a JSP, you just edit and the Web server takes care of the rest.



BEA WebLogic Platform 7
BEA WebLogic Platform 7
ISBN: 0789727129
EAN: 2147483647
Year: 2003
Pages: 360

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net