2011-02-15 98 views
3

如何在Tomcat上共享午餐JSP项目?我复制WebContent文件夹到webapp文件夹的Apache,但它无法找到我的jsp页面,但如果我将jsp更改为jsf(index.jsf)可以正常工作。我怎么解决这个问题?在Apache Tomcat上运行JSF项目

的web.xml:

<?xml version="1.0" encoding="UTF-8"?> 
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5"> 
    <display-name>Graph</display-name> 
    <welcome-file-list> 
    <welcome-file>index.jsp</welcome-file> 
    </welcome-file-list> 
    <servlet> 
    <servlet-name>Faces Servlet</servlet-name> 
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class> 
    <load-on-startup>1</load-on-startup> 
    </servlet> 
    <servlet-mapping> 
    <servlet-name>Faces Servlet</servlet-name> 
    <url-pattern>/faces/*</url-pattern> 
    </servlet-mapping> 
    <context-param> 
    <param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name> 
    <param-value>resources.application</param-value> 
    </context-param> 
    <context-param> 
    <description>State saving method: 'client' or 'server' (=default). See JSF Specification 2.5.2</description> 
    <param-name>javax.faces.STATE_SAVING_METHOD</param-name> 
    <param-value>client</param-value> 
    </context-param> 
    <context-param> 
    <description> 
    This parameter tells MyFaces if javascript code should be allowed in 
    the rendered HTML output. 
    If javascript is allowed, command_link anchors will have javascript code 
    that submits the corresponding form. 
    If javascript is not allowed, the state saving info and nested parameters 
    will be added as url parameters. 
    Default is 'true'</description> 
    <param-name>org.apache.myfaces.ALLOW_JAVASCRIPT</param-name> 
    <param-value>true</param-value> 
    </context-param> 
    <context-param> 
    <description> 
    If true, rendered HTML code will be formatted, so that it is 'human-readable' 
    i.e. additional line separators and whitespace will be written, that do not 
    influence the HTML code. 
    Default is 'true'</description> 
    <param-name>org.apache.myfaces.PRETTY_HTML</param-name> 
    <param-value>true</param-value> 
    </context-param> 
    <context-param> 
    <param-name>org.apache.myfaces.DETECT_JAVASCRIPT</param-name> 
    <param-value>false</param-value> 
    </context-param> 
    <context-param> 
    <description> 
    If true, a javascript function will be rendered that is able to restore the 
    former vertical scroll on every request. Convenient feature if you have pages 
    with long lists and you do not want the browser page to always jump to the top 
    if you trigger a link or button action that stays on the same page. 
    Default is 'false' 
</description> 
    <param-name>org.apache.myfaces.AUTO_SCROLL</param-name> 
    <param-value>true</param-value> 
    </context-param> 
    <servlet> 
    <servlet-name>faces</servlet-name> 
    <servlet-class>org.apache.myfaces.webapp.MyFacesServlet</servlet-class> 
    <load-on-startup>1</load-on-startup> 
    </servlet> 
    <servlet> 
    <servlet-name>UploadServlet</servlet-name> 
    <servlet-class>controler.UploadServlet</servlet-class> 
    </servlet> 
    <servlet-mapping> 
    <servlet-name>faces</servlet-name> 
    <url-pattern>*.jsf</url-pattern> 
    </servlet-mapping> 
    <servlet-mapping> 
    <servlet-name>faces</servlet-name> 
    <url-pattern>*.faces</url-pattern> 
    </servlet-mapping> 
    <servlet-mapping> 
    <servlet-name>UploadServlet</servlet-name> 
    <url-pattern>/Upload</url-pattern> 
    </servlet-mapping> 
    <listener> 
    <listener-class>org.apache.myfaces.webapp.StartupServletContextListener</listener-class> 
    </listener> 
</web-app> 

错误: 型状态报告

message /Graph/index.jsp

description The requested resource (/Graph/index.jsp) is not available.

+1

您需要添加更多信息。 – 2011-02-15 10:06:28

回答

10

这不是问题。这是预期的行为。你只是误解了基本的Servlet API的工作原理。你已经配置了JSF标准FacesServlet听匹配/faces/*网址,并已配置的Apache MyFaces的具体MyFacesServlet听匹配*.jsf*.faces网址。

要获得JSF运行,必须通过匹配FacesServlet的映射的URL打开浏览器页面。既然你已经一个index.jsp文件和你的上下文路径是Graph,并且已经在三个不同的URL模式配置了两个JSF的servlet,您可以通过以下网址打开JSP的事实:


表示您的配置不必要的过于复杂。摆脱MyFacesServlet条目及其所有关联的URL映射(servlet名称为faces)。只要坚持标准FacesServlet并使用其映射,或改为改为它。我个人推荐使用*.jsf

<servlet> 
    <servlet-name>facesServlet</servlet-name> 
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class> 
    <load-on-startup>1</load-on-startup> 
</servlet> 
<servlet-mapping> 
    <servlet-name>facesServlet</servlet-name> 
    <url-pattern>*.jsf</url-pattern> 
</servlet-mapping> 

然后你可以通过http://localhost:8080/Graph/index.jsf打开页面。


无关的具体问题,您welcome-file不会这样的。 Tomcat会在该页面上发出HTTP 404错误(页面/资源未找到)。你需要指定index.jsfwelcome-file和在同一文件夹提供一个具体的,但index.jsf文件作为index.jsp。通过这种方式,Tomcat将被愚弄,该文件存在并通过调用http://localhost:8080/Graph来显示页面。


如果您关注的是,它是可以打开通过其*.jsp扩展JSF页面,这将导致一个RuntimeException: FacesContext not found,你反倒没有一个JSP文件,该文件是送达普通的香草,那么你可以限制直接访问JSP文件由以下安全约束在web.xml

<security-constraint> 
    <display-name>Restrict direct access to JSP files</display-name> 
    <web-resource-collection> 
     <web-resource-name>JSP files</web-resource-name> 
     <url-pattern>*.jsp</url-pattern> 
    </web-resource-collection> 
    <auth-constraint /> 
</security-constraint> 

(在JSF 2.0,这是顺便说不需要了,默认视图技术的Facelets有可能在FacesServlet上只是*.xhtml地图,这与Facelets文件的默认扩展名相同)

0

您可以使用Tomcat管理器应用程序部署

http://tomcatIP:8080/manager/html

那里你可以上传你的应用程序,它应该运行开箱即用 如果您不知道应输入什么用户名和密码,则必须配置您的tomcat-users.xml

相关问题