我正在尝试学习仅将没有 .jsp 文件的预编译 JSF 部署到 Tomcat6,但遇到 HTTP Status 404 resource not found 错误。以下是我在测试中执行的步骤(抱歉,有点冗长):
Web 应用程序的名称是'precompile'。
在预编译之前包含 2 个JSF (.jsp) 文件的原始WAR使用以下 url 进行部署和测试:
http://localhost:8080/precompile/faces/
从 index.jsp 导航到第二页也可以。
使用Tomcat 6 Jasper 2 文档中描述的 ant 脚本预编译部署的 Web 应用程序,命令行为:
ant -Dtomcat.home="%CATALINA_HOME%" -Dwebapp.path="%CATALINA_HOME%\webapps\precompile"
构建成功。
web.xml
并通过添加addWebXmlMappings="true"
in jasper 任务自动合并生成的 web.xml。web.xml 包含在这篇文章的下部。所有 .jsp 文件仍在 Web 应用程序中,在 Web 浏览器中再次测试 - 确定。
停止Tomcat。从 Web 应用程序中删除 2 个 .jsp 文件。启动tomcat。在 Web 浏览器中测试,进入 index.jsp 是可以的,但是导航到第二页会遇到 HTTP 状态 404 请求的资源不可用错误:
HTTP Status 404 - /modules/m1/pages/page1.jsp not found
在 tomcat 控制台中未显示错误。
web.xml
: _
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<filter>
<filter-name>RichFacesFilter</filter-name>
<filter-class>org.ajax4jsf.Filter</filter-class>
</filter>
<filter-mapping>
<filter-name>RichFacesFilter</filter-name>
<servlet-name>Faces Servlet</servlet-name>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
<dispatcher>INCLUDE</dispatcher>
</filter-mapping>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<!-- JSPC servlet mappings start -->
<servlet>
<servlet-name>org.apache.jsp.index_jsp</servlet-name>
<servlet-class>org.apache.jsp.index_jsp</servlet-class>
</servlet>
<servlet>
<servlet-name>org.apache.jsp.modules.m1.pages.page1_jsp</servlet-name>
<servlet-class>org.apache.jsp.modules.m1.pages.page1_jsp</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>org.apache.jsp.index_jsp</servlet-name>
<url-pattern>/index.jsp</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>org.apache.jsp.modules.m1.pages.page1_jsp</servlet-name>
<url-pattern>/modules/m1/pages/page1.jsp</url-pattern>
</servlet-mapping>
<!-- JSPC servlet mappings end -->
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
<display-name>precompile</display-name>
<listener>
<listener-class>com.sun.faces.config.ConfigureListener</listener-class>
</listener>
<context-param>
<param-name>javax.faces.CONFIG_FILES</param-name>
<param-value>/WEB-INF/faces-config.xml</param-value>
</context-param>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<login-config>
<auth-method>BASIC</auth-method>
</login-config>
</web-app>
如需参考faces-config.xml
:
<?xml version="1.0"?>
<faces-config version="1.2" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xi="http://www.w3.org/2001/XInclude"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee /web-facesconfig_1_2.xsd">
<managed-bean>
<managed-bean-name>indexBean</managed-bean-name>
<managed-bean-class>com.mypack.IndexBean</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>
<managed-bean>
<managed-bean-name>page1Bean</managed-bean-name>
<managed-bean-class>com.mypack.Page1Bean</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>
<navigation-rule>
<navigation-case>
<from-outcome>page1</from-outcome>
<to-view-id>/modules/m1/pages/page1.jsp</to-view-id>
</navigation-case>
</navigation-rule>
</faces-config>
我怀疑这可能是由于 servlet 映射错误,但我不确定。
我做错了什么?少了什么东西?
感谢您阅读这个长问题。
2011 年 6 月 21 日更新:
附加信息
如果我使用以下网址访问 page1:
http://localhost:8080/precompile/faces/modules/m1/pages/page1.jsp
我会得到一个Cannot find FacesContext
错误:
SEVERE: Servlet.service() for servlet org.apache.jsp.modules.m1.pages.page1_jsp threw exception
java.lang.RuntimeException: Cannot find FacesContext
at javax.faces.webapp.UIComponentClassicTagBase.getFacesContext(UIComponentClassicTagBase.java:1855)
at javax.faces.webapp.UIComponentClassicTagBase.setJspId(UIComponentClassicTagBase.java:1672)
at org.apache.jsp.modules.m1.pages.page1_jsp._jspx_meth_f_005fview_005f0(page1_jsp.java:94)
at org.apache.jsp.modules.m1.pages.page1_jsp._jspService(page1_jsp.java:70)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.ajp.AjpAprProcessor.process(AjpAprProcessor.java:427)
at org.apache.coyote.ajp.AjpAprProtocol$AjpConnectionHandler.process(AjpAprProtocol.java:384)
at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1555)
at java.lang.Thread.run(Thread.java:619)
看起来编译的文件page1_jsp
也有问题。
可能是什么原因?以前有没有人成功部署过没有 .jsp 的预编译 JSF?介意分享一下它是怎么做的吗?
谢谢你。