Java ebook

Páginas: 16 (3956 palabras) Publicado: 2 de julio de 2011
,jsppr.9600 Page 1 Friday, September 7, 2001 2:51 PM

JavaServer Pages Pocket Reference

The JavaServer Pages™ (JSP) specification is built on top of the Java™ servlet specification and is intended to provide for better separation of the presentation (e.g., HTML markup) and business logic (e.g., database operations) parts of web applications. JSP is supported by all major web and applicationservers. A partial listing of JSP-compliant products is available at Sun Microsystems’ JSP web page: http://java.sun.com/products/jsp/ A JSP page is a web page that contains both static content, such as HTML, and JSP elements for generating the parts that differ with each request, as shown in Figure 1. The default filename extension for a JSP page is .jsp. Everything in the page that’s not a JSPelement is called template text. Template text can be in any format, including HTML, WML, XML, and even plain text. Since HTML is by far the most common web page language in use today, most of the descriptions and examples in this text are HTMLbased. You should be aware, though, that JSP has no dependency on HTML. Template text is not interpreted at all; it’s passed straight through to the browser.JSP is therefore wellsuited to serve any markup language. When a JSP page request is processed, the static template text and the dynamic content generated by the JSP elements are merged, and the result is sent as the response to the client.

1

,jsppr.9600 Page 2 Friday, September 7, 2001 2:51 PM

The following information was saved: User Name: Email Address:

JSP elementtemplate text

JSP element

template text

JSP element template text JSP element

template text

Figure 1. Template text and JSP elements

JSP Processing
Before a JSP page is sent to a browser, the server must process all the JSP elements it contains. This processing is performed by a web container, which can be either a native part of a web server or a separate product attached to theweb server. The web container turns the JSP page into a Java servlet, then executes the servlet. Converting the JSP page into a servlet (known as the JSP page implementation class) and compiling the servlet take place in the translation phase. The web container initiates the translation phase for a JSP page automatically when the first request for the page is received. The translation phase takes abit of time, of course, so users may notice a slight delay the first time they request a JSP page. The translation phase can also
2 | JavaServer Pages Pocket Reference

,jsppr.9600 Page 3 Friday, September 7, 2001 2:51 PM

be initiated explicitly, to avoid hitting the first user with the delay. This is referred to as precompilation. The web container is also responsible for invoking the JSPpage implementation class to process each request and generate responses. This is called the request processing phase. The two phases are illustrated in Figure 2.
hello.jsp Server with JSP Container Client
Rea d

2
Translation phase helloServlet.java

1

GET /hello.jsp HTTP/1.0 200 OK Hello!

3 Generate 6
Exec ute

Compile

4 5
helloServlet.class Request processing phaseFigure 2. JSP page translation and processing phases

As long as the JSP page remains unchanged, the translation phase is skipped. When the page is modified, it goes through the translation phase again. Let’s look at a simple example. In the tradition of programming books, we start with an application that writes “Hello World” (with a twist—it also shows the current time on the server):
HelloWorld Hello World It's and all is well.

This JSP page produces the result shown in Figure 3.
JSP Processing | 3

,jsppr.9600 Page 4 Friday, September 7, 2001 2:51 PM

Figure 3. The output from the Hello World page

This is as simple as it gets. The code represented by the JSP element (which we have highlighted in bold in the code) is executed, and the result is combined with the...
Leer documento completo

Regístrate para leer el documento completo.

Estos documentos también te pueden resultar útiles

  • Ebook
  • ebook
  • Ebook
  • tecnologia del ebook
  • TIC: ebook
  • Java
  • Java
  • Java

Conviértase en miembro formal de Buenas Tareas

INSCRÍBETE - ES GRATIS