JSP basics

JSP is a presentation layer technology that sits on top of a Java servlets model and makes working with HTML easier. Like ASP, it allows you to mix static HTML content with server-side scripting to produce dynamic output. By default, JSP uses Java as its scripting language; however, the specification allows other languages to be used, just as ASP can use other languages (such as JavaScript and VBScript). While JSP with Java will be more flexible and robust than scripting platforms based on simpler languages like JavaScript and VBScript, Java also has a steeper learning curve than simple scripting languages.

To offer the best of both worlds - a robust web application platform and a simple, easy-to-use language and tool set - JSP provides a number of server-side tags that allow developers to perform most dynamic content operations without ever writing a single line of Java code. So developers who are only familiar with scripting, or even those who are simply HTML designers, can use JSP tags for generating simple output without having to learn Java. Advanced scripters or Java developers can also use the tags, or they can use the full Java language if they want to perform advanced operations in JSP pages.

JSP Extends Servlets

In a sense, JSP technology does not provide new core technologies - everything that can be done with a JSP page, can also be done by writing a servlet. Servlets have access to the same set of Java APIs as JSP. Pages created with JSP technology are, in fact, compiled into servlets, so they cannot be capable of anything inherently different.

What JSP pages do, however, is enable a different, more efficient development methodology and simplify ongoing maintenance. This is because JSP technology truly separates the page design and static content from the logic used to generate the dynamic content.

JSP Request Model

Now let's take a look at how HTTP requests are processed under the JSP model. In the basic request model, a request is sent directly to a JSP page. Figure 1 illustrates the flow of information in this model. JSP code controls interactions with JavaBeans components for business and data logic processing, and then displays the results in dynamically generated HTML mixed with static HTML code.

 


 Basic JSP request model

 

                           


The beans depicted can be JavaBeans or EJB components. Other, more complicated request models include calling out to other JSP pages or Java servlets from the requested JSP page.