Chapter: Internet & World Wide Web HOW TO PROGRAM - JavaServer Pages (JSP): Bonus for Java™ Developers

Study Material, Lecturing Notes, Assignment, Reference, Wiki description explanation, brief detail

JavaServer Pages Overview

There are four key components to JSPs: directives, actions, scriptlets and tag libraries.

JavaServer Pages Overview

 

There are four key components to JSPs: directives, actions, scriptlets and tag libraries. Di-rectives are messages to the JSP container that enable the programmer to specify page set-tings, to include content from other resources and to specify custom tag libraries for use in a JSP. Actions encapsulate functionality in predefined tags that programmers can embed in a JSP. Actions often are performed based on the information sent to the server as part of a particular client request. They also can create Java objects for use in JSP scriptlets. Script-lets, or scripting elements, enable programmers to insert Java code that interacts with com-ponents in a JSP (and possibly other Web application components) to perform request processing. Tag libraries are part of the tag extension mechanism that enables programmers to create custom tags. Such tags enable programmers to manipulate JSP content. These JSP component types are discussed in detail in subsequent sections.

 

In many ways, Java Server Pages look like standard XHTML or XML documents. In fact, JSPs normally include XHTML or XML markup. Such markup is known as fixed-tem-plate data or fixed-template text. Fixed-template data often help a programmer decide whether to use a servlet or a JSP. Programmers tend to use JSPs when most of the content sent to the client is fixed template data and only a small portion of the content is generated dynamically with Java code. Programmers use servlets when only a small portion of the content sent to the client is fixed-template data. In fact, some servlets do not produce con-tent. Rather, they perform a task on behalf of the client, then invoke other servlets or JSPs to provide a response. Note that in most cases, servlet and JSP technologies are inter-changeable. As with servlets, JSPs normally execute as part of a Web server. The server often is referred to as the JSP container.

When a JSP-enabled server receives the first request for a JSP, the JSP container trans-lates that JSP into a Java servlet that handles the current request and future requests to the JSP. If there are any errors compiling the new servlet, these errors result in translation-time errors. The JSP container places the Java statements that implement the JSP’s response in method _jspService at translation time. If the new servlet compiles properly, the JSP container invokes method _jspService to process the request. The JSP may respond directly to the request or may invoke other Web application components to assist in pro-cessing the request. Any errors that occur during request processing are known as request-time errors.

Overall, the request/response mechanism and life cycle of a JSP is the same as that of a servlet. JSPs can define methods jspInit and jspDestroy (similar to servlet methods init and destroy), which the JSP container invokes when initializing a JSP and terminating a JSP, respectively. JSP programmers can define these methods using JSP declarations—part of the JSP scripting mechanism.

 

Study Material, Lecturing Notes, Assignment, Reference, Wiki description explanation, brief detail


Copyright © 2018-2020 BrainKart.com; All Rights Reserved. Developed by Therithal info, Chennai.