Chapter 4. JSP Engine

Table of Contents

4.1. Overview
4.2. Apache Tomcat Jasper
4.3. JSP Engine Functions
4.3.1. Reloading JSP Files
4.3.2. Precompiling JSP Files
4.3.3. JSP Compilation and Execution in Memory
4.4. Configuring JSP Engines
4.4.1. Configuring at the Web Engine Level
4.4.2. Configuring jeus-web-dd.xml
4.4.3. Web Context Options for JSP Backward Compatibility

This chapter describes the concepts, functions, and configurations of the JSP engine.

The JSP engine is embedded in web engines. It exists in each web context. This section does not explain JSP standards. Refer to the JSP standards for more information about creating a JSP engine.

When web clients request JSP pages, the JSP engine finds the pages and converts them to servlets. During the servlets conversion process, the engine creates Java files and SMAP files, and compiles the Java files to create class files that will be used for the services.

If JSP pre-compilation is not used, JSP files are compiled the first time the request is received, so when the first request happens, the response might take more time because the access to the OS file system occurs frequently.

In an environment where network-attached storage (NAS) is used, if there are many files that require compilation because of tags and JSP include relations, many requests will be sent to the NAS, which delays the response. Depending on the NAS driver operation, a JSP file with a size of 0 might be read without generating a java.io.IOException. Jasper reads files using the JVM file I/O API, so parsing of the JSP file will fail.

[Warning]

Internal testing shows that the javac library that is provided by the Oracle JDK is not thread-safe, so the property jeus.servlet.jsp.compile-java-source-concurrently is provided and the default value is false. When the request threads compile .java files, they set a lock at the JVM scope.

If the javac library provided by the JDK is thread-safe, the property jeus.servlet.jsp.compile-java-source-concurrently can be set to "true" in jeus-web-dd.xml as follows. If so, verify that the JSP files compile normally in a multi-threaded environment.

    <properties>
        <property>
            <key>jeus.servlet.jsp.compile-java-source-concurrently</key>
            <value>true</value>
        </property>
    </properties>

JEUS has always included Jasper, the Tomcat JSP parser, but changed the package name and included it in jeus.jar. Starting from JEUS 7, the package is named org.apache.jasper, but it is packaged as a separate library jasper.jar. The library is located in the following path:

$JEUS_HOME/lib/system/jasper.jar

When using Jasper, consider the following:

  • The jasper.jar library is modified for JEUS, so it must not be overwritten with the Tomcat library. If it is, the server will not start.

  • When an application uses Tomcat's jasper.jar in WEB-INF/lib, the <webinf-first> option in jeus-web-dd.xml must be set to 'true'. Otherwise, the jasper.jar classes from JEUS will be used, which can cause unpredictable results.

Differences Between Tomcat Jasper and JEUS Jasper

As explained above, JEUS modifies parts of the version of Jasper that are provided by Tomcat, so consider the following:

  • JEUS provides functions including in-memory JSP complication, which Tomcat Jsaper does not provide.

  • JEUS does not use the tag handler pool or the page context pool.

64KB Method Size Limitation when Compiling Java Source

If there is too much content in a single .jsp file when creating JSP, the size of a method in the file may exceed 64KB. In this case, the .java file cannot be compiled by a Java compiler because it violates the Java Language Standards.

The 64KB limit can be avoided if most of the content is in the string format, such as SQL statements or HTML tags. Configure the web.xml file as follows:

<servlet>
    <servlet-name>jeus.servlet.servlets.JspServlet</servlet-name>
    <servlet-class>jeus.servlet.servlets.JspServlet</servlet-class>
    <init-param>
      <param-name>genStringAsCharArray</param-name>
      <param-value>true</param-value>
    </init-param>
</servlet>
<servlet-mapping>
    <servlet-name>jeus.servlet.servlets.JspServlet</servlet-name>
    <url-pattern>*.jsp</url-pattern>
</servlet-mapping>

If a file with too many Java codes fails to be compiled, separate responses using the <jsp:include> element. The following is an example of using the <jsp:include> element.

<body>
    Template Page<br/>
    <jsp:include page="module_one.jsp" />
    <jsp:include page="module_two.jsp" />
</body>

The JSP engine provides reloading, pre-compilation functions, graceful reloading, as well as JSP compiling and running at the memory.

JSP files are usually used for views rather than for logic, so users often want to change the JSP files while still running the service, so web applications that use JSP are often deployed as a directory instead of a WAR.

Warning

When a native library is loaded through System.LoadLibrary() method within the JSP file, JSP reloading may fail.

To reload the JSP, a class loader must be created per JSP and the class loader must be replaced when reloading. The references for the native library is managed by the JVM in the class loader. When the class loader instance goes through the garbage collection, the reference gets cleaned up. Thus, if the JVM GC does not occur when the JSP class loader needs to be replaced, JSP reloading will fail. Since the JVM GC cannot be controlled from JEUS and this issue occurs due to the internal structure of the JVM, it cannot be resolved.

Therefore, it is recommended to load a native library only once at server startup. When a native library is modified, JEUS cannot guarantee a successful reloading of the library within the JVM.

JSP in Web Context

JSP files are located in the root directory of the web context. They can be packaged as a separate directory or in the 'META-INF/resources/ that is defined in Servlet 3.0' directory.

JSP files can be found in the 'META-INF/resources/' directory if the directory is in the *.jar library files of the 'WEB-INF/lib/' directory. JSP files in 'WEB-INF/' cannot be executed because for security reasons web clients cannot access the files in the 'WEB-INF/' directory.

Refer to "3.2.2. Web Context Structure (WAR File Structure)" for more information about the internal structure of web contexts.

Note

For more information about the files in the 'META-INF/resources/' directory, refer to the resource APIs in http://docs.oracle.com/javaee/6/api/javax/servlet/ServletContext.html.

The JSP engine can be configured in WebAdmin or in each application's jeus-web-dd.xml file.

The JSP engine of a web engine can be configured in WebAdmin.

  1. Click [Servers] from the left menu to go to the list of servers. Click a server from the list to go to the server configuration screen. From the screen, go to the [Engine] > [Web Engine] > [Jsp Engine] tab.


  2. Click [Lock & Edit] to change to configuration mode.

  3. Configure the basic information on the Jsp Engine screen and click [OK].


    The following describes each item.

    ItemDescription
    Jsp Work Dir

    Root directory where Java source files created by JSP are saved.

    The files are not directly created in the root directory. Directories are created using the domain name, server name, and web application name. The files are created in these directories. In other words, class files are not shared by different web engines.

    If 'Compile Output Dir' is not set, class files are created in the same path. By default, the class files are created in the following location:

    • EAR application

      INTERNALGENERATED_HOME/ear1/web1/__jsp_work
    • Standalone web module

      INTERNALGENERATED_HOME/web1/__jsp_work
    Java Compiler

    Command that executes the Java compiler that compiles JSP Java source to servlet classes. Since the default value is the most efficient, it is not recommended to change this setting.

    Compile Output Dir

    Location of the class files that are created by compiling the Java files, which were created by the JSP parser. The class files are used to execute the services. If not set, they are created in the same directory as the Java files.

    Compile OptionServlet compiler
    Compile EncodingEncoding option used to compile the servlet source files created by parsing JSP files.
    Check Included Jspfile

    Checks if a JSP file has been modified. If it has been modified, the JSP file will be compiled.

    If set to 'true', besides the requested JSP pages, all JSP files and tag files that are included with the <%@ include file=”xxx.jsp” %> directive are checked for modification and then compiled.

    Keep GeneratedOption to keep the Java and SMAP files created by the JSP parser. This is useful for debugging. If set to 'false', files will be deleted after being created. For performance reasons, it is not recommended to change this setting.
    Use In Memory CompilationFunction used to create, compile, and execute .java and .class files when JSP files that are running need to be recompiled. Refer to "4.3.3. JSP Compilation and Execution in Memory" for detailed information.

  4. After completing the configurations, click [Apply Changes] to apply the changes. The following result is displayed.


In JEUS 4 and 5, non-standard functions are provided for applications that were developed before servlet 2.3, and the syntax does not conform to the JSP syntax. Starting from JEUS 6, syntax checking is more strict and the JSP parser has been replaced with a Jasper-based JSP parser to support JSP 2.1, but the existing JSP parser is also supported for backward compatibility with existing JSP.

Errors may occur when deploying web modules that ran successfully in JEUS 4 and 5. To use the current specifications such as JSP 2.1, check the error messages that are generated when compiling the JSP, and modify the module accordingly.

To use the existing modules without using the current specifications, add the following configurations to jeus-web-dd.xml. This will allow using the JSP parser, which is compatible with JEUS 4 and 5, in the web context.


The options in jeus-web-dd.xml are applied to the web context, but it is also possible to apply them to the web engine or the virtual host. To apply the options at the engine level, set the following VM option. Refer to JEUS Server Guide. "2.2. Adding Servers" for more information about VM options.

-Djeus.servlet.jsp.modern=false

VM options can be replaced at the virtual host or web context level, and the settings in jeus-web-dd.xml are applied last. If the option is not set in jeus-web-dd.xml, the default configuration of the parent will be applied.

Using this option is only recommended when backward compatibility is required. For new application developments, it is recommended to use the current standards

Note

For information about other options, refer to JEUS Reference Book. "1.6. Web Engine Properties".