JSP

<Home>

 

The JavaServer Pages technology enables you to generate dynamic web content, such as HTML, DHTML, XHTML, and XML files, to include in a Web application. JSP files are one way to implement server-side dynamic page content. JSP files allow a Web server, such as Apache Tomcat, to add content dynamically to your HTML pages before they are sent to a requesting browser.

When you deploy a JSP file to a Web server that provides a servlet engine, it is preprocessed into a servlet that runs on the Web server. This is in contrast with client-side JavaScript™ (within <SCRIPT> tags), which is run in a browser. A JSP page is ideal for tasks that are better suited to execution on the server, such as accessing databases or calling Enterprise Java™ beans.

You can create and edit a JSP file in the HTML editor by adding your own text and images using HTML, JSP tagging, or JavaScript, including Java source code inside of scriptlet tags. Typically, JSP files have the file extension .jsp. Additionally, the JSP specification suggests that JSP fragment files should have file extension .jspf. If this convention is not followed, the JSP validator will treat JSP fragments as regular standalone JSP files, and compilation errors might be reported.

The Sun Microsystems JSP 1.2 Specification provides the ability to create custom JSP tags. Custom tags simplify complex actions and provide developers with greater control over page content. Custom tags are collected into a library (taglib). A tag library descriptor file (taglib.tld) is an XML document that provides information about the tag library, including the taglib short name, library description, and tag descriptions. Refer to the Sun Microsystems JSP 1.2 Specification for more details.

To use JSP 1.2 custom taglibs, you can import the tag library .tld and .jar files into your project to use them, or associate them as Web Library projects. You can also reference a TLD file by using a URI.

Servlets

Servlets are server-side Java™ programs that use the Sun Microsystems Java Servlet API and its associated classes and methods, as defined in the Sun Microsystems Java Servlet 2.3 Specification. These Java programs extend the functionality of a Web server by generating dynamic content and responding to Web client requests. When a browser sends a request to the server, the server can send the request information to a servlet, so that the servlet can construct the response that is sent back to the browser.

Just as applets run on a Web browser and extend the browser's capabilities, servlets run on a Java-enabled Web server and extend the server's capabilities. Because of their flexibility and scalability, servlets are commonly used to enable businesses to connect databases to the Web.

Although a servlet can be a completely self-contained program, you can split application development into two portions:

Using this paradigm, you may choose to have business logic handled by Java beans, the presentation logic handled by JavaServer Pages (JSP) or HTML files, and the HTTP protocol handled by a servlet.

Note: JSP files can be used to manage both the presentation and business logic for a Web application. JSP files use structured markup for presentation, and supply servlet model behavior at run time.

You can develop, debug, and deploy servlets, set breakpoints within servlet objects, and step through code to make changes that are dynamically folded into the running servlet on a running server, without having to restart each time.

Listeners

Listeners are new feature in the Sun Microsystems Java™ Servlet 2.3 Specification. A listener can be used to monitor and react to events in a servlet's life-cycle by defining methods that get invoked when life-cycle events occur. Support for application level events is defined in the Java Servlet Specification 2.3.

Application event listeners are classes that implement one or more of the servlet event listener interfaces. Servlet event listeners support notification for state changes in the ServletContext and HttpSession objects, specifically: