JavaServer Pages (JSP) 运行时重新装入设置

当修改了 JavaServer Pages 文件或它的依赖项时,可以在运行时转换和编译 JSP 文件。这称为 JSP 重新装入。

最佳实践 最佳实践: 使用 Rational Application Developer 等组装工具来修改 IBM 扩展和绑定文件。可以使用 IBM Bindings and Extensions Conversion Tool for Multi-Platforms 将模块中的扩展和绑定文件从 XMI 转换为 XML。bprac

通过 WEB-INF/ibm-web-ext.xmiWEB-INF/ibm-web-ext.xml 文件中的 reloadEnabled JSP 引擎参数启用 JSP 重新装入。

ibm-web-ext.xmi 示例:
<jspAttributes xmi:id=“JSPAttribute_1” name=“reloadEnabled” value=“true”/>
ibm-web-ext.xml 示例:
<?xml version=“1.0” encoding=“UTF-8”?>
<web-ext
   xmlns=“http://websphere.ibm.com/xml/ns/javaee”
   xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance”
   xsi:schemaLocation=“http://websphere.ibm.com/xml/ns/javaee http://websphere.ibm.com/xml/ns/javaee/ibm-web-ext_1_0.xsd”
      version=“1.0”>
	
   <jsp-attribute name=“trackDependencies” value=“true” />
   <jsp-attribute name=“disableJspRuntimeCompilation” value=“true” />
   <jsp-attribute name=“reloadEnabled” value=“true”/>

   <reload-interval value=“5”/>
   <auto-encode-requests value=“false”/>
   <auto-encode-responses value=“false”/>
   <enable-directory-browsing value=“false”/>
   <enable-file-serving value=“false”/>
   <pre-compile-jsps value=“false”/>
   <enable-reloading value=“true”/>
   <enable-serving-servlets-by-class-name value=“false” />	
</web-ext>
支持的配置 支持的配置: 对于 IBM® 扩展文件和绑定文件,根据您使用的是 Java EE 5 之前的应用程序或模块还是 Java™ EE 5 或之后的应用程序或模块,.xmi 或 .xml 文件扩展名有所不同。IBM 扩展文件或绑定文件将命名为 ibm-*-ext.xmi 或 ibm-*-bnd.xmi,其中 * 是扩展文件或绑定文件的类型,例如,app、application、ejb-jar 或 web。存在下列条件:
  • 对于使用 V5 之前的 Java EE 版本的应用程序或模块,文件扩展名必须是 .xmi。
  • 对于使用 Java EE 5 或更高版本的应用程序或模块,文件扩展名必须是 .xml。如果应用程序或模块中包含 .xmi 文件,那么产品将忽略这些 .xmi 文件。

然而,Java EE 5 或更高版本的模块可以在包含 Java EE 5 之前的文件并使用 .xmi 文件扩展名的应用程序中存在。

ibm-webservices-ext.xmiibm-webservices-bnd.xmiibm-webservicesclient-bnd.xmiibm-webservicesclient-ext.xmiibm-portlet-ext.xmi 文件继续使用 .xmi 文件扩展名。

sptcfg
下表包含针对生产环境和开发环境建议的重新装入设置。
表 1. 针对生产环境和开发环境建议的重新装入设置。. 重新装入设置
配置属性 生产环境设置 开发环境设置
reloadEnabled False true
reloadInterval 不适用(如果 reloadEnabled 为 false,那么忽略它) 大约 5 秒
trackDependencies 不适用(如果 reloadEnabled 为 false,那么忽略它) true - 或者,如果依赖性不会更改,请将它设置为 false 以减少响应时间
disableJspRuntimeCompilation true - 或者,如果 JSP 文件没有进行预编译并因此在第一次请求时需要进行编译,请将它设置为 false。 False

reloadEnabled 参数的缺省值为 true。如果 reloadEnabled 参数设置为 true,那么当 JSP 文件和它的类文件具有不同的时间戳记时,将在运行时重新装入该 JSP 文件。另外,如果 trackDependencies 设置为 true,而且自最后生成 JSP 类文件之后,JSP 文件的任何依赖项的时间戳记发生了更改,那么重新装入该 JSP 文件。如果 reloadEnabled 参数设置为 false,仍会在首次请求 JSP 文件时在需要的情况下编译该文件,除非参数 disableJspRuntimeCompilation 为 true。例如,当 disableJspRuntimeCompilation 和 reloadEnabled 均为 false 时,如果 JSP 文件的类文件已过时,那么将在首次请求该 JSP 文件时对其进行编译。在后续请求该文件时将不会编译,即使修改了 JSP 源文件或者删除了类文件也是如此,除非 reloadEnabled 为 true。

重新装入时间间隔

重新装入时间间隔通过 reloadInterval JSP 引擎参数设置。

ibm-web-ext.xmi 示例:
<jspAttributes xmi:id=JSPAttribute_1 name=reloadInterval value=5/>
ibm-web-ext.xml 示例:
<?xml version=“1.0” encoding=“UTF-8”?>
<web-ext
   xmlns=“http://websphere.ibm.com/xml/ns/javaee”
   xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance”
   xsi:schemaLocation=“http://websphere.ibm.com/xml/ns/javaee http://websphere.ibm.com/xml/ns/javaee/ibm-web-ext_1_0.xsd”
      version=“1.0”>
	
   <jsp-attribute name=“trackDependencies” value=“true” />
   <jsp-attribute name=“disableJspRuntimeCompilation” value=“true” />
   <jsp-attribute name=“reloadInterval” value=“5”/>

   <reload-interval value=“5”/>
   <auto-encode-requests value=“false”/>
   <auto-encode-responses value=“false”/>
   <enable-directory-browsing value=“false”/>
   <enable-file-serving value=“false”/>
   <pre-compile-jsps value=“false”/>
   <enable-reloading value=“true”/>
   <enable-serving-servlets-by-class-name value=“false” />	
</web-ext>

如果启用了重新装入,那么 reloadInterval 参数值将确定检查(检查 JSP 文件是否过时)之间的时间延迟。例如,如果 reloadInterval 为 5,那么在发生 JSP 文件请求时,JSP 引擎是否执行 JSP 文件过时检查取决于当前请求离上一次检查的时间,只在超过了五秒后引擎才执行检查。一旦超过 reloadInterval,执行重新装入检查,然后该 JSP 文件的重新装入时间间隔计时器重置为 0。reloadInterval 越大,JSP 引擎检查是否需要重新装入 JSP 文件的频率越小。

依赖性跟踪

依赖性跟踪通过 trackDependencies JSP 引擎参数设置。

ibm-web-ext.xmi 示例:
<jspAttributes xmi:id=“JSPAttribute_1” name=“trackDependencies” value=“true”/>
ibm-web-ext.xmi 示例:
<?xml version=“1.0” encoding=“UTF-8”?>
<web-ext
   xmlns=“http://websphere.ibm.com/xml/ns/javaee”
   xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance”
   xsi:schemaLocation=“http://websphere.ibm.com/xml/ns/javaee http://websphere.ibm.com/xml/ns/javaee/ibm-web-ext_1_0.xsd”
      version=“1.0”>
	
   <jsp-attribute name=“trackDependencies” value=“true” />
   <jsp-attribute name=“disableJspRuntimeCompilation” value=“true” />
   <jsp-attribute name=“reloadInterval” value=“5”/>

   <reload-interval value=“5”/>
   <auto-encode-requests value=“false”/>
   <auto-encode-responses value=“false”/>
   <enable-directory-browsing value=“false”/>
   <enable-file-serving value=“false”/>
   <pre-compile-jsps value=“false”/>
   <enable-reloading value=“true”/>
   <enable-serving-servlets-by-class-name value=“false” />	
</web-ext>
如果启用重新装入,trackDependencies 参数值确定 JSP 引擎是否跟踪对请求的 JSP 文件的依赖项以及对 JSP 文件本身的修改。下面是 JSP 引擎跟踪的三种类型的相关性:
  • JSP 文件中静态包含的文件
  • JSP 文件中引用的标记文件(不包括 JAR 文件中的标记文件)
  • JSP 文件中引用的 TLD(不包括 JAR 文件中的 TLD)
依赖性跟踪信息总是包含在生成的类文件中,即使 trackDependencies 为 false 也是一样。JSP 引擎或批处理编译器不使用该信息,除非 trackDependencies 参数为 true。这意味着您可以启用依赖性跟踪而不必重新编译 JSP 文件。

例如,toplevel.jsp 文件静态地包含 footer.jspf 文件。编译 toplevel.jsp 文件时,到 footer.jspf 文件的路径以及它的时间戳记都存储在 toplevel.jsp 的类文件中。结果是,修改 footer.jspf 文件并请求 toplevel.jsp 文件。既然超出了 toplevel.jsp 文件的重新装入时间间隔,JSP 引擎就把存储在类文件中的时间戳记与磁盘上的 footer.jspf 文件时间戳记进行比较。因为时间戳记不一样,所以编译 toplevel.jsp 文件,从而使对 footer.jspf 文件的修改生效。为了执行依赖性跟踪,在运行时请求 JSP 文件或者在批处理编译器处理 JSP 文件时,trackDependencies 值必须设为 true。

禁用编译

通过 disableJspRuntimeCompilation JSP 引擎参数设置禁用 JavaServer Pages 的运行时编译。

ibm-web-ext.xmi 示例:
<jspAttributes xmi:id=“JSPAttribute_1” name=“disableJspRuntimeCompilation” value=“true”/>
ibm-web-ext.xml 示例:
<?xml version=“1.0” encoding=“UTF-8”?>
<web-ext
   xmlns=“http://websphere.ibm.com/xml/ns/javaee”
   xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance”
   xsi:schemaLocation=“http://websphere.ibm.com/xml/ns/javaee http://websphere.ibm.com/xml/ns/javaee/ibm-web-ext_1_0.xsd”
      version=1.0>
	
   <jsp-attribute name=“trackDependencies” value=“true” />
   <jsp-attribute name=“disableJspRuntimeCompilation” value=“true” />
   <jsp-attribute name=“reloadInterval” value=“5”/>

   <reload-interval value=“5”/>
   <auto-encode-requests value=“false”/>
   <auto-encode-responses value=“false”/>
   <enable-directory-browsing value=“false”/>
   <enable-file-serving value=“false”/>
   <pre-compile-jsps value=“false”/>
   <enable-reloading value=“true”/>
   <enable-serving-servlets-by-class-name value=“false” />	
</web-ext>

如果 disableJspRuntimeCompilation 参数设置为 true,那么 JSP 引擎在运行时不转换和编译 JSP 文件;JSP 引擎只装入预编译的类文件。JSP 源文件不需要为了装入类文件而存在。如果此选项设置为 true,那么可以在没有 JSP 源文件的情况下安装应用程序,但必须具有预编译的类文件。有一个同名的 Web 容器定制属性,可用来确定安装在服务器中的所有 Web 模块的行为。如果同时设置了 Web 容器定制属性和 JSP 引擎选项,那么 JSP 引擎选项优先。将 disableJspRuntimeCompilation 参数设置为 true 时,会自动将 reloadEnabled 设置为 false。

重新装入处理顺序

图 1 中显示当 trackDependencies 为 false 时,与 JSP 文件重新装入相关的处理顺序。

图 1. 当 trackDependencies 为 false 时,重新装入处理顺序。重要

当 trackDependencies 为 true 时,JSP 引擎会执行额外的文件系统处理来确定自最近一次转换和编译 JSP 文件以来是否有任何 JSP 文件的相关性发生了更改。图 2 显示标注为 ““JSP class file outdated?””的流程图中,“否路径上执行的额外处理。您可以看到当 disableJspRuntimeCompilation 为 true 时所走的路径是效率最高的路径。

图 2. 当 trackDependencies 为 true 时,执行额外重新装入处理。重要

指示主题类型的图标 参考主题



时间戳记图标 最近一次更新时间: last_date
http://www14.software.ibm.com/webapp/wsbroker/redirect?version=cord&product=was-nd-mp&topic=rweb_jspreloading
文件名:rweb_jspreloading.html