在Apache Tomcat上运行JSF项目

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

web.xml中:

   Graph  index.jsp   Faces Servlet javax.faces.webapp.FacesServlet 1   Faces Servlet /faces/*   javax.servlet.jsp.jstl.fmt.localizationContext resources.application   State saving method: 'client' or 'server' (=default). See JSF Specification 2.5.2 javax.faces.STATE_SAVING_METHOD client    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' org.apache.myfaces.ALLOW_JAVASCRIPT true    If true, rendered HTML code will be formatted, so that it is 'human-readable' ie additional line separators and whitespace will be written, that do not influence the HTML code. Default is 'true' org.apache.myfaces.PRETTY_HTML true   org.apache.myfaces.DETECT_JAVASCRIPT false    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'  org.apache.myfaces.AUTO_SCROLL true   faces org.apache.myfaces.webapp.MyFacesServlet 1   UploadServlet controler.UploadServlet   faces *.jsf   faces *.faces   UploadServlet /Upload   org.apache.myfaces.webapp.StartupServletContextListener   

错误:输入状态报告

消息/Graph/index.jsp

description请求的资源(/Graph/index.jsp)不可用。

那不是问题。 这是预期的行为。 您只是误解了基本的Servlet API的工作原理。 您已将JSF标准FacesServlet配置为侦听匹配/faces/* URL,并且已配置Apache MyFaces特定的MyFacesServlet以侦听匹配*.jsf*.faces

要使JSF运行,您必须通过与FacesServlet的映射匹配的URL在浏览器中打开页面。 鉴于您有一个index.jsp文件,并且您的上下文路径是Graph ,并且您已经在三种不同的URL模式上配置了两个JSF servlet,您可以通过以下URL打开JSP:

  • http:// localhost:8080 / Graph / faces / index.jsp (调用FacesServlet
  • http:// localhost:8080 / Graph / index.jsf (调用MyFacesServlet
  • http:// localhost:8080 / Graph / index.faces (调用MyFacesServlet

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

  facesServlet javax.faces.webapp.FacesServlet 1   facesServlet *.jsf  

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


与具体问题无关,您的welcome-file将无法正常工作。 Tomcat会在其上发出HTTP 404错误(找不到页面/资源)。 您需要将index.jsf指定为welcome-file并在与index.jsf相同的文件夹中提供具体但空的 index.jsf文件。 这样Tomcat就会被文件存在,并通过调用http:// localhost:8080 / Graph来显示页面。


如果您担心可以通过*.jsp扩展名打开JSF页面,这会导致RuntimeException: FacesContext not found并且您实际上没有一个JSP文件可以提供普通服务,那么您可以限制直接访问通过web.xml的以下安全性约束来访问JSP文件:

  Restrict direct access to JSP files  JSP files *.jsp    

(在JSF 2.0中,这是不再需要的方式,使用默认的视图技术Facelets,可以将FacesServlet映射到*.xhtml ,这与Facelets文件的默认扩展名相同)

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

HTTP:// tomcatIP:8080 /经理/ HTML

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