Jetty: Configuring JSP Support

Source: Internet
Author: User
Tags glassfish

Choosing a JSP implementation

Starting with Jetty-9.2, use Apache Jasper as the default JSP container implementation. The GlassFish Jasper is used in the previous version and can be used in later versions.
Jetty Release the default activation JSP module, default, module settings to Apache Jasper. In order to use GlassFish Jasper instead, edit the $jetty_home/start.d/jsp.mod and change the following line:

# # Jetty JSP module# [depend]servletjsp-impl/${jsp-impl}-jsp [ini-template]# JSP Configuration # Select JSP Implementatio  N, choices are#   glassfish:the Reference Implementation #               default in jetty <= 9.1#   Apache    : The Apache  Version #               default jetty >= 9.2jsp-impl=apache # to use a NON-JDK compiler for JSPs compilation when using GlassFish Uncomment next line#-dorg.apache.jasper.compiler.disablejsr199=true

Note that some of the JSP's characteristics can be implemented using a JSP container that relies on your choice. Also note that you cannot precompile one container of JSPs and deploy another.

Pre-compilation

You can precompile the JSP according to the instruction manual provided by your chosen JSP container (GlassFish or Apache). Or if you choose to use MAVEN, you can use the Jetty-jspc-maven plugin to do it for you.
If you precompile your JSP and customize the output package prefix (default is org.apache.jsp), you should configure your WebApp context to tell jetty about your custom registration. You can use the initialization parameters of the servlet context Org.eclipse.jetty.servlet.jspPackagePrefix to do this.
For example, suppose you precompile your JSP and use the custom package prefix COM.ACME, you will add in Web. xml:

<context-param>  <param-name>org.eclipse.jetty.servlet.jspPackagePrefix</param-name>  <param-value>com.acme</param-value></context-param>

Note: Jetty's maven plugin Jetty-jspc-maven-plugin and jetty-maven-plugin can only be used with Apache Jasper

Compile the JSP at run time

Depending on the different JSP containers you choose, the configuration items and compilation attributes will be different.

Apache JSP Container

By default, the Apache JSP container will look for Eclipse Java Compiler (JDT). JETTY released its own one in $jetty_home/lib/apache-jsp. If you wish to use a different compiler, you will need to configure the Compilerclassname initial parameters in Jspservlet and bring the class name.
The following table is an introduction to the parameters of Apache Jspservlet:

Understanding Apache Jspservlet Parameters
Initial Parameters Description Default Value Webdefault.xml
Classpath The Classpath used for JSP compilation. Only used if the Org.apache.catalina.jsp_classpath context property in Jetty is not set. - -
Classdebuginfo Include debugging information in the class file TRUE -
Checkinterval The interval of the background recompilation check, in seconds. Only Development=false is used. 0 -
Development Development=true, each request is re-compiled for review. See Modificationtestinterval TRUE -
Displaysourcefragment Whether to include the source fragment in the exception information TRUE -
Erroronusebeaninvalidclassattribute When the value of the Class property is not a valid bean class in a usebean behavior, does it produce an error TRUE -
Fork Should Ant fork the Java compilation of its JSP page? TRUE FALSE
keepgenerated Do you want to keep the generated Java files? TRUE -
Trimspaces Should the space between the instruction and the behavior be cropped? FALSE -
Enablepooling Determine if the label processor pool is activated TRUE -
Engineoptionsclass Allows the specified options class to be used to configure Jasper. Otherwise, the default embeddedservletoptions will be used - -
Mappedfile Support for mapped Files. Generate a servlet that has a print declaration for each line of the JSP file TRUE -
Suppresssmap The generation of SMAP information for JSR45 debugging FALSE -
Dumpsmap Dump SMAP JSR45 information to a file FALSE -
Genstraschararray Option to generate strings FALSE -
Ieclassid When using the <jsp:plugin> tag, the Class-id value is sent to Internet Explorer Clsid:8ad9c840-044e-11d1-b3e9-00805f499d93 -
Maxloadedjsps The maximum value of a JSP that a web app can load. If this value is exceeded, the least recently used JSP will be uninstalled. 0 or a negative value indicates no limit. -1 -
Jspidletimeout The maximum time, in seconds, that a JSP is idle before being unloaded. A value of 0 or negative means never unload. -1 -
ScratchDir The folder that the servlet is generated in - -
Compilerclassname If not set, the default is the Eclipse JDT compiler. - -
Compiler Used if the Eclipse JDT compiler cannot be found in classpath. It is the class name of the compiler that ant should call. - -
Compilertargetvm The target VM that the compiler expects. 1.7 -
Compilersourcevm Set the source compatibility level for the JDT compiler. 1.7 -
Javaencoding The compilation uses the encoding method. UTF8
Modificationtestinterval If development=true, the interval of the recompile check is triggered by a request. 4 -
Xpoweredby Generates a x-powered-by response header. FALSE FALSE
Recompileonfail If a JSP fails to compile, modificationtestinterval should be ignored and trigger the next recompile attempt? Used only in development mode, the default is stopped because the compilation can be costly and causes too many resources to be used. - -

Glassfish JSP Container

In order to compile the. jsp file into Java classes, you need a Java compiler. If you are using a full JDK, you can get the Java compiler from the JVM, otherwise you can do it from a third-party jar.
The default GlassFish JSP container attempts to use the JDK's compiler. Note: When using the JDK compiler, the system does not save your class file to disk unless you initialize the parameter with Savebytecode, which is described below.
If you do not have a full JDK, you can configure Eclipse Java Compiler under the JETTY $jetty_home/lib/jsp/folder. You need to define a system property that prevents the GlassFish JSP engine from using the compiler in the JVM by default.
When using a standalone Standard Edition, the best way is to use the org.apache.jasper.compiler.disablejsr199 system attribute, in the JSP module:

-dorg.apache.jasper.compiler.disablejsr199=true

Or for embedded use, simply define this as a normal system attribute.

Configuration

The JSP engine has some configuration parameters. Some parameters affect precompilation only, while some affect run-time pre-compilation checks. There are also different parameters between different versions of the JSP engine. The configuration parameters, their meanings, and their default settings are listed below. All parameters are defined in the Org.apache.jasper.JspServlet instance of Webdefault.xml:

Understanding GlassFish JSP Parameters
Initial Parameters Description Default Value Webdefault.xml
Development Development=true, the recompile check is performed on each request. Look at Modificationtestinterval. TRUE -
Fork Should Ant fork the Java compilation of its JSP page? TRUE FALSE
keepgenerated Do you want to keep the resulting Java files? FALSE -
Savebytecode If the class file is generated as a byte arrays, should they be saved to disk at the end of the compilation? FALSE -
Trimspaces Should the gap between the instruction and the behavior be cropped? FALSE -
Enablepooling Determines whether the label processor pool is activated. TRUE -
Mappedfile Support for mapped Files. Generate a servlet that has a print declaration for each line of the JSP file TRUE -
Senderrortoclient If False, the stack trajectory, etc., is sent to the standard error instead of the client's browser. FALSE -
Classdebuginfo Include the debugging information in the class file. TRUE -
Checkinterval The interval of the background recompilation check, in seconds. Only Development=false is used. 0 -
Suppresssmap The generation of SMAP information for JSR45 debugging FALSE -
Dumpsmap Dump SMAP JSR45 information to a file FALSE -
Genstraschararray Option to generate strings FALSE -
Genstrasbytearray Option to generate strings TRUE -
Defaultbuffernone - FALSE -
Erroronusebeaninvalidclassattribute - FALSE -
ScratchDir The folder to which the servlet is generated. JETTY set this value according to the [/display/jetty/temporary+directories work dir] set for WebApp - -
Compiler Determined at run time. For jetty, Eclipse JDT compiler. - -
Compilertargetvm The target VM that the compiler expects. 1.5 -
Compilersourcevm Set the source compatibility level for the JDT compiler. 1.5 -
Javaencoding The compilation uses the encoding method. UTF8 -
Modificationtestinterval If development=true, the interval of the recompile check is triggered by a request. 0 -
Xpoweredby Generates a x-powered-by response header. FALSE FALSE
Useprecompiled/use-precompiled - FALSE -
Validating/enabletldvalidation Whether the label file is validated against the schema (schema). FALSE -
Reload-interval If reload-interval=0, do not do JSP run-time check, otherwise set check interval, regardless of development=true or development=false. - -
Initial-capacity/initialcapacity The initial capacity of the hash mapping table mapping JSP to class and JSP files - -

There is usually a lot of confusion in relation to development, Checkinterval, and Modificationtestinterval parameters, and JSP runtime recompilation. Here are the various options that are broken out:

1) Check JSP file recompilation for each request

<init-param>        <param-name>development></param-name>        <param-value>true> </param-value></init-param>

2) Check approximately every n seconds and trigger timed calculations by request. The following is a check every 60 seconds:

<init-param>        <param-name>development></param-name>        <param-value>true> </param-value></init-param><init-param>        <param-name>modificationTestInterval> </param-name>        <param-value>60></param-value></init-param>

3) do not check, but compile the JSP on first use. (Note that the "reload-interval" parameter corresponds to the shorthand for the "Development=false" and "checkinterval=0" combinations):

<init-param>        <param-name>reload-interval></param->        <param-value>-1></ Param-value></init-param>

4) do not make any requests when checking, but start a background thread to perform a check every n seconds. The following example checks every 60 seconds:

<init-param>        <param-name>development></param-name>        <param-value>false> </param-value> </init-param> <init-param>         <param-name>checkinterval></ Param-name>         <param-value>60></param-value></init-param>
Modify Configuration

Regardless of which JSP container you are using, there are several options for modifying the Jspservlet configuration.

Heavy Duty Webdefault.xml

You can copy JETTY's own $jetty_home/etc/webdefault.xml, modify it, and replace it with its own version. Here's how to use the jetty Maven plugin to reach this goal:

<plugin>  <groupId>org.eclipse.jetty</groupId>  <artifactid>jetty-maven-plugin </artifactId>  <configuration>    <webApp>      <defaultsdescriptor>src/main/ Resources/webdefault.xml</defaultsdescriptor>    </webApp></plugin>

If you are using the JETTY release, you want to change the JSP settings to one or more of your webapp, copy the $jetty_home/etc/webdefault.xml file to a place, modify it, and then use the context The XML file sets this file for your WebApp defaultsdescriptor. Here is an example:

<configure class=> "Org.eclipse.jetty.webapp.WebAppContext" >   <set name=> "ContextPath" >/foo </Set>  <set name=> "war" ><systemproperty name=> "Jetty.home" >default=> "." />/webapps/foobar.war</set>  <set name=> "Defaultsdescriptor" >/home/smith/dev/ Webdefault.xml</set>  </Configure>

If you want to change the JSP settings to all WebApp, edit the $jetty_home/etc/webdefaults.xml directly.

Configuring a JSP Servlet in Web. xml

Another option is to add an entry for Jspservlet in your webapp's web-inf/web.xml, changing or increasing the initialization parameters. You can also increase (but not remove) servlet-mappings. You can use the entry in the $jetty_home/etc/webdefault.xml as a starting point.

<servlet id=> "JSP" > <servlet-name>jsp</servlet-name> <servlet-class> Org.apache.jasper.servlet.jspservlet</servlet-class> <init-param> <param-name>logverbosityleve        l</param-name> <param-value>DEBUG</param-value> </init-param> <init-param> <param-name>fork</param-name> <param-value>>false</param-value> </init-param&gt    ; <init-param> <param-name>keepgenerated</param-name> <param-value>>true</param- Value> </init-param> ... <load-on-startup>0</load-on-startup> </servlet> <s Ervlet-mapping> <servlet-name>jsp</servlet-name> <url-pattern>*.jsp</url-pattern> < Url-pattern>*.jspf</url-pattern> <url-pattern>*.jspx</url-pattern> &LT;URL-PATTERN&GT;*.XSP </url-pattern> <url-pattern>*. Jsp</url-pattern> <url-pattern>*. Jspf</url-pattern> <url-pattern>*. Jspx</url-pattern> <url-pattern>*. xsp</url-pattern> </servlet-mapping> <servlet id=> "My-servlet" > <servlet-name>myservlet </servlet-name> <servlet-class>com.acme.servlet.MyServlet</servlet-class> ...
Using the JSTL Tag library

The JavaServer Pages standlard Tag Library (JSTL) is part of the JETTY release version (in $jetty_home/lib/jsp).

Using the JSF tag library

Information about using the JSF tag library is provided below.

Using the JSF tag library in Jetty Publishing

If you want to use JSF in your webapp, you need to copy the JSF implementation jar (the jar containing the Meta-inf/*.tld file in your chosen JSF implementation) into the Jetty Shared container Library folder. You can put them into the Lib folder to match the JSP container of your choice (or GlassFish JSP's $jetty_home/lib/jsp, or Apache JSP $jetty_home/lib/apache-jsp), or put them into the $ Jetty_home/lib/ext.

Using the JSF tag library with the jetty Maven plugin

You should make your JSF jar dependent on the plugin instead of WebApp itself. For example:

<plugin>  <groupId>org.eclipse.jetty</groupId>  <artifactid>jetty-maven-plugin </artifactId>  <configuration>     <webApp>       <contextpath>/${artifactid}</ contextpath>     </webApp>     <scanIntervalSeconds>5</scanIntervalSeconds>  </ configuration>  <dependencies>    <dependency>      <groupid>com.sun.faces</ groupid>      <artifactId>jsf-api</artifactId>      <version>2.0.8</version>    </dependency>    <dependency>      <groupId>com.sun.faces</groupId>      < artifactid>jsf-impl</artifactid>      <version>2.0.8</version>   </dependency>  </dependencies></plugin>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.