Tuesday, May 29, 2012

Improving Page Compilation Performance

The first time a page is requested, it undergoes several conversions: from JSP/JHTML to Java code to HTML. That first transformation from JSP/JHTML to Java code causes a slight delay in performance that is easily avoided by precompiling your pages. There are several ways to precompile all files in a directory:

  1.  Use the Java compiler provided with your application server to precompile JSPs

  2.  Use the JHTML batch compiler to precompile JHTML pages.

You can precompile individual JSPs at application startup by specifying them in your Web application deployment descriptor. Here’s an example of what you’d add for a page called MyPage.jsp to web.xml in enclosing <web-app> tags:


<servlet>
  <servlet-name>MyPage.jsp</servlet-name>

  <jsp-file>/path/to/jsp/MyPage.jsp</jsp-file>

  <load-on-startup>1</load-on-startup>
</servlet>



An explanation of each tag is as follows:

    <servlet-name> identifies the servlet to be compiled

    <jsp-file>
identifies the path to the servlet

    <load-on-startup> identifies the order in which this servlet should be compiled

No comments:

Popular Posts