Home : Tutorials : JSP Tutorial


Presenting Output Using JSP™ Technology

By Sudhir Ancha

If you wanted to show lot of HTML from your browser and you didn't want to type all the standard presentation HTML from your Java (Servlet) Code, then Java Server Pages are a boon for you. It eases the work f showing the HTML Text to the Browser.

If the layout of a page is its main feature and there is little or no processing involved to generate the page, you may find it easier to use a JSP alone for the interaction. 

Think of JSPs and servlets as opposite sides of the same coin. Each can perform all the tasks of the other, but each is designed to excel at one task at the expense of the other. The strength of servlets is in processing and adaptability, and since they are Java files you can take advantage of integrated development environments while you are writing them. However, performing HTML output from them involves many cumbersome println statements that must be coded by hand. Conversely, JSPs excel at layout tasks because they are simply HTML files and can be created with HTML editors, though performing computational or processing tasks with them can be awkward. Choose the tool that is right for the job you undertake. 


How JSP's Work :

A JSP is made up of JSP elements and template data. Template data refers to anything not in the JSP specification, including text and HTML tags. For example, the minimal JSP, which requires no processing by the JSP engine, is a static HTML page. 

The JSP Engine compiles JSPs into HTTP servlets the first time they are called. This makes them available to the application environment as standard objects, and it also enables them to be called from a client using a URL.

JSPs run inside a Java process on the server. This process, called a JSP engine, is responsible for interpreting JSP-specific tags and performing the actions they specify in order to generate dynamic content. This content, along with any template data surrounding it, is assembled into a page for output and returned to the caller.

The response object contains a reference to the calling client, and this is where a JSP presents the page that it creates. If you call a JSP from a servlet using the forward() method from the RequestDispatcher interface, forward() provides the response object as a parameter to the JSP. If a JSP is invoked directly from a client, the response object is provided by the server that is managing the relationship with the caller. 

In either case, the page is automatically returned to the client through the reference provided in the response object. You do not have to write any code to return a page to a client. 

You can create JSPs that are not a part of any particular application. These JSPs are considered to be part of a generic application. JSPs and some other application components can be updated at run time without restarting the server, making it easy to change the look and feel of your application without stopping service. For more information, see

Home  Next 

Click Here For Servlets Tutorial


Home : Tutorials : JSP Tutorial

 

Copyright© 1998-2004 All Rights Reserved. No portion of this site may be reproduced or redistributed without prior written permission from VistaEdge Technologies

All registered trademarks appearing on this site are the property of their respective owners. Java is a trademark or registered trademark of Sun Microsystems, Inc. in the United States and other countries. This site is not connected to Sun Microsystems, Inc. and is not sponsored by Sun Microsystems, Inc.