如何将没有.jsp的预编译JSF部署到Tomcat6?
我正在尝试学习仅将预编译的 JSF 没有 .jsp 文件部署到 Tomcat6,但遇到 HTTP Status 404 资源未找到错误。以下是我在测试中执行的步骤(抱歉,有点长):
Web 应用程序的名称是“预编译”。
在预编译之前包含 2 个 JSF (.jsp) 文件的原始 WAR 使用以下 URL 进行部署和测试:
http://localhost:8080/precompile/faces/
从index.jsp导航到第二页也可以。
使用 Tomcat 中描述的 ant 脚本预编译已部署的 Web 应用程序6 Jasper 2文档,命令行为:
ant -Dtomcat.home="%CATALINA_HOME%" -Dwebapp.path="%CATALINA_HOME%\webapps\precompile"
构建成功。通过在 jasper 任务中添加
addWebXmlMappings="true"
, generated_web.xml 会自动合并到web.xml
中。 web.xml 包含在本文的下半部分。在所有 .jsp 文件仍在 Web 应用程序中的情况下,在 Web 浏览器中再次测试 - 确定。
停止 tomcat。从 Web 应用程序中删除 2 个 .jsp 文件。启动雄猫。在 Web 浏览器中进行测试,访问 index.jsp 正常,但导航到第二个页面会遇到 HTTP Status 404 requested resources is not available 错误:
HTTP 状态 404 - 未找到 /modules/m1/pages/page1.jsp
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 吗?介意分享一下它是如何完成的吗?
谢谢。
I'm trying to learn to deploy only precompiled JSF without .jsp files to Tomcat6, but hit HTTP Status 404 resource not found error. Below are the steps I did in my test (sorry, a bit lengthy):
The name of web application is 'precompile'.
The original WAR containing 2 JSF (.jsp) files before precompilation is deployed and tested ok using this url:
http://localhost:8080/precompile/faces/
Navigating from index.jsp to the second page is also OK.
Precompile the deployed web application using the ant script described in Tomcat 6 Jasper 2 Documentation, the command line is:
ant -Dtomcat.home="%CATALINA_HOME%" -Dwebapp.path="%CATALINA_HOME%\webapps\precompile"
Build is successful. And the generated_web.xml is merged to
web.xml
automatically by adding theaddWebXmlMappings="true"
in jasper task. The web.xml is included at the lower part of this post.With all the .jsp files still in the web application, test again in web browser - OK.
Stop tomcat. Delete the 2 .jsp files from the web application. Start tomcat. Test in web browser, getting to index.jsp is OK, but navigating to the second page hits a HTTP Status 404 requested resource is not available error:
HTTP Status 404 - /modules/m1/pages/page1.jsp not found
Not error shown in tomcat console.
The 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>
If need to refer to 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>
I suspect it may be due to mistake in servlet mapping, but I'm not sure.
What did I do wrong? What's missing?
Thanks for reading this long question.
Update 21 June 2011:
Additional info
If I access page1 with the following url:
http://localhost:8080/precompile/faces/modules/m1/pages/page1.jsp
I will get a Cannot find FacesContext
error:
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)
Looks like the compiled file page1_jsp
is having problem too.
What can be the cause? Has anyone done deploying precompiled JSF without .jsp successfully before? Mind to share how it's done?
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论