如何在Tomcat上进行午餐JSP项目?我将WebContent
文件夹复制到Apache的webapp
文件夹但是找不到我的jsp页面,但是如果我将jsp更改为jsf(index.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>
错误: 类型状态报告
消息/Graph/index.jsp
description请求的资源 (/Graph/index.jsp)不可用。
答案 0 :(得分:10)
这不是问题。这是预期的行为。您只是误解了基本的Servlet API的工作原理。您已将JSF标准FacesServlet
配置为侦听与/faces/*
匹配的网址,并且您已配置特定于Apache {是} MyFacesServlet
以侦听与*.jsf
和*.faces
匹配的网址
要使JSF运行,您必须通过与FacesServlet
的映射匹配的URL在浏览器中打开页面。鉴于您有一个index.jsp
文件并且您的上下文路径是Graph
并且您已经在三种不同的URL模式上配置了两个JSF servlet,您可以通过以下URL打开JSP: / p>
FacesServlet
)MyFacesServlet
)MyFacesServlet
)说,您的配置不必要地过于复杂。摆脱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.jsf
指定为welcome-file
,并在与index.jsf
相同的文件夹中提供具体但空 index.jsp
文件。通过这种方式,Tomcat将被愚弄文件存在并通过调用http://localhost:8080/Graph来显示页面。
如果您担心可以通过*.jsp
扩展名打开JSF页面,这会导致RuntimeException: FacesContext not found
并且您实际上没有一个JSP文件可以提供普通的,那么您可以通过web.xml
中的以下安全性约束来限制对JSP文件的直接访问:
<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文件的扩展名)
答案 1 :(得分:0)
您可以使用tomcat管理器部署应用程序
http://tomcatIP:8080/manager/html
你可以上传你的应用程序,它应该是开箱即用的 如果您不知道应输入的用户名和密码,则必须配置tomcat-users.xml