JSP technology

JSP技术的主要特点有:

  • A language for developing JSP pages, which are text-based documents that describe how to process a request and construct a response

  • An expression language for accessing server-side objects

  • Mechanisms for defining extensions to the JSP language

JSP的生命周期(The life cycle of a JSP page)

1.Tanslation and Compilation(翻译和编译)

当一个请求(Request)被映射到一个JSP页面,Web Container首先检查这个JSP页面的Servlet是否比JSP页面旧。如果是,Web Container首先将JSP页面翻译成Servlet类,并编译成.class文件。During development, one of the advantages of JSP pages over servlets is that the build process is performed automatically.

在翻译阶段,各种不同类型的数据以不同的方式处理。静态数据直接输入到response stream里。JSP element处理方式如下:

  • Directives(伪指令)用来指示Web Container怎样处理和执行JSP页面。
  • Scripting elements被插入到JSP页面的Servlet class中。
  • Expression language expressions are passed as parameters to calls to the JSP expression evaluator.
  • jsp:[set|get]Property elements are converted into method calls to JavaBeans components.
  • jsp:[include|forward]elements are converted into invocations of the Java Servlet API.
  • The jsp:plugin element is converted into browser-specific markup for activating an applet.
  • Custom tags are converted into calls to the tag handler that implements the custom tag.

 Both the translation and the compilation phases can yield errors that are observed only when the page is requested for the first time. If an error is encountered during either phase, the server will return JasperException and a message that includes the name of the JSP page and the line where the error occurred.

After the page has been translated and compiled, the JSP page’s servlet (for the most part) follows the servlet life cycle described in Servlet Life Cycle:

  1. If an instance of the JSP page’s servlet does not exist, the container:

    1. Loads the JSP page’s servlet class

    2. Instantiates an instance of the servlet class

    3. Initializes the servlet instance by calling the jspInit method

  2. The container invokes the _jspService method, passing request and response objects.

If the container needs to remove the JSP page’s servlet, it calls the jspDestroy method.

2.Execution

You can control various JSP page execution parameters by using page directives.

 

原文Javaee 5 tutorial.

posted @ 2012-05-03 21:49  cuillgln  阅读(292)  评论(0编辑  收藏  举报