JavaServer Pages (JSPs)

JavaServer Pages (JSPs) are based on the concept of server-side parsing. A JavaServer Page is an HTML page with Java statements embedded in it. The JSP specification defines certain special tags that can be embedded within the HTML page. In a normal working scenario, the JSP pages are parsed by a JSP compiler within the application server and converted into a Java servlet with the generated code embedded within the Java servlet as a set of Java statements. The generated Java servlet is then compiled as a normal servlet and loaded into the Java servlet container. The Java servlet is then used to process the user requests.

In effect, the JSP specification simplifies the development of Java servlets, thus enabling specialized user interface (UI) application component providers to focus on building Web-enabled UIs for their applications. More importantly, JSP allows you to separate the development of the content and business logic of a Web application from the look and feel of the application.

The JSP specification defines the following set of tags that can be used by application component providers:

  • Directive tag A directive tag embedded in a JSP is used to issue directives to the JSP compiler that compiles the JSP.

  • Declaration tag A declaration tag can be used by the application component provider to define variables or methods that need to be put outside the service() method of the final generated Java servlet.

  • Expression tag In order to use Java values or variables directly in the JSP, you can use the expression tag.

  • Scriptlet tag The scriptlet tag is the most important tag in the JSP specification because it enables the actual embedding of Java code within an HTML page. An application component provider can write entire processing routines within the scriptlet tags.

  • Custom tag The final set of tags that the JavaServer Page specification defines is the embedding of custom tags. Because the JSP compiler cannot process these tags on its own, a special set of classes called the JSP tag library must be built by the application component provider to support the processing of the custom tags. You will be taking a quick look at the JSP tag library in the next subsection.

JSP Tag Library

The JSP specification does allow developers to extend the JSP functionality and add custom tags in the JSP page. To develop custom tags, you need to write a custom JSP tag library to support the custom tags because the JSP engine that parses the JSP will have no idea how to interpret and process the custom tags.

The primary advantage offered by building a JSP tag library is the encapsulation of complex processing code in a separate Java class. This encapsulation also enables the processing logic and, hence, the custom tags in the JSP tag library to be reusable across different JSPs in the application. The behavior of the custom tags (its processing logic) can be customized with the ability to pass attributes to the Java class performing the processing for the custom tags. This is an added benefit to the reusable feature of custom tags. Moreover, as a part of building a JSP tag library, the JSP specification defines a set of interfaces and classes that need to be implemented or used by an application component provider. This ensures that the JSP tag libraries that an application component provider builds are compliant with the J2EE specification.

Visual composing tools are available from different vendors to create JSPs as well as to build custom tag libraries and embed them in the JSPs. Because these tools conform to the JSP specification, an application component provider can build JSPs and JSP tag libraries using any of the J2EE-compliant tools and can deploy the JSPs and JSP custom tag libraries in any J2EE-compliant containers or application servers without encountering any nonconformance problems.



Sams Teach Yourself BEA WebLogic Server 7. 0 in 21 Days
Sams Teach Yourself BEA WebLogic Server 7.0 in 21 Days
ISBN: 0672324334
EAN: 2147483647
Year: 2002
Pages: 339

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