IBM Support

JSP compilation in WebSphere Application Server Community Edition

Question & Answer


Question

How do I configure JSP compilation in WebSphere Application Server Community Edition?

Cause

WebSphere Application Server Community Edition uses Tomcat as the Web container. When Web applications containing JSPs are deployed on the server, WebSphere Application Server Community Edition uses Jasper to compile JSPs and stores the compiled JSPs in the following directory:

<wasce_home>/var/temp

By default, when the server is restarted, all the compiled JSPs are deleted. Consequently, the server has to recompile JSPs whenever any JSPs are accessed by users after the server is restarted. The following technote explains how to configure WebSphere Application Server Community Edition so that JSPs are compiled once and retained even after server is restarted.

Answer

  • Configuration at the server scope
    WebSphere Application Server Community Edition can be configured to retain the compiled JSPs of all Web applications running in the server across server restarts. The procedure is as follows.
    1. Open the following file in a text editor:

    2. <wasce_home>/var/catalina/conf/web.xml

    3. Add the following parameters to org.apache.jasper.servlet.JspServlet:

    4. <init-param>
      <param-name>scratchdir</param-name>
      <param-value>
         ../var/catalina/worker1/
      </param-value>
      </init-param>
      <init-param>
      <param-name>keepgenerated</param-name>
      <param-value>false</param-value>
      </init-param>

    5. Create a sub-directory named worker1 in the following directory:

    6. <wasce_home>/var/catalina/conf

    7. JSPs from all the Web applications are compiled once into worker1 directory and persisted across server restarts.

  • Configuration at the application scope
    If users want to configure retaining the compiled JSPs for a single Web application, the following procedure needs to followed.
    1. Open the web.xml file of the Web application in a text editor.

    2. Copy the following contents.

    3. <servlet>
      <servlet-name>jsp</servlet-name>
      <servlet-class>
        org.apache.jasper.servlet.JspServlet
      </servlet-class>
      <init-param>
        <param-name>development</param-name>
        <param-value>false</param-value>
      </init-param>
      <init-param>
        <param-name>fork</param-name>
        <param-value>false</param-value>
      </init-param>
      <init-param>
        <param-name>scratchdir</param-name>
        <param-value>
         ../var/catalina/worker1/
        </param-value>
      </init-param>
      <init-param>
        <param-name>keepgenerated</param-name>
        <param-value>false</param-value>
      </init-param>
      <init-param>
        <param-name>xpoweredBy</param-name>
         <param-value>false</param-value>
      </init-param>
      <init-param>
         <param-name>engineOptionsClass</param-name>
         <param-value>
            org.apache.geronimo.jasper.JspServletOptions
         </param-value>  
      </init-param>
        <load-on-startup>3</load-on-startup>
      </servlet>
      <servlet-mapping>
        <servlet-name>jsp</servlet-name>
        <url-pattern>*.jsp</url-pattern>
      </servlet-mapping>
      <servlet-mapping>
        <servlet-name>jsp</servlet-name>
        <url-pattern>*.jspx</url-pattern>
      </servlet-mapping>

    4. Create a sub-directory named worker1 in the following directory:

    5. <wasce_home>/var/catalina/conf

    6. JSPs from the configured application are compiled once into worker1 directory and retained intact across server restarts.

  • JSP precompilation
    Before deploying Web applications on WebSphere Application Server Community Edition, users can precompile the JSPs into servlets using JASPER libraries shipped with the WebSphere Application Server Community Edition. A sample ANT script is available here. The ANT script can be configured to use JASPER libraries shipped with WebSphere Application Server Community Edition. This technique precompiles all the JSPs into servlets and generates required servlet mapping entries to be copied to the web.xml file of the Web application. The generated servlet classes can be packaged with the Web application and deployed on the server.

[{"Product":{"code":"SS6JMN","label":"WebSphere Application Server Community Edition"},"Business Unit":{"code":"BU053","label":"Cloud & Data Platform"},"Component":"Tomcat","Platform":[{"code":"PF002","label":"AIX"},{"code":"PF016","label":"Linux"},{"code":"PF027","label":"Solaris"},{"code":"PF033","label":"Windows"}],"Version":"2.1.1.2;2.1.1.1;2.1.0.1;2.1;2.0.0.3;2.0.0.2;2.0.0.1;2.0","Edition":"Entry;Enhanced;Elite","Line of Business":{"code":"LOB45","label":"Automation"}}]

Document Information

Modified date:
15 June 2018

UID

swg21303765