Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/364.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在ApacheTomcat上运行JSF项目_Java_Tomcat_Jsf 2 - Fatal编程技术网

Java 在ApacheTomcat上运行JSF项目

Java 在ApacheTomcat上运行JSF项目,java,tomcat,jsf-2,Java,Tomcat,Jsf 2,如何在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.

如何在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>

图表
index.jsp
Facesservlet
javax.faces.webapp.FacesServlet
1.
Facesservlet
/面孔/*
javax.servlet.jsp.jstl.fmt.localizationContext
资源.应用
状态保存方法:“客户端”或“服务器”(=默认值)。参见JSF规范2.5.2
javax.faces.STATE_保存方法
客户
此参数告诉MyFaces是否应允许使用javascript代码
呈现的HTML输出。
如果允许使用javascript,则命令链接锚定将具有javascript代码
提交相应的表格。
如果不允许使用javascript,则保存信息和嵌套参数的状态
将作为url参数添加。
默认值为“true”
org.apache.myfaces.ALLOW_JAVASCRIPT
真的
如果为true,则将格式化呈现的HTML代码,使其“可读”
i、 e.将写入额外的行分隔符和空格,但不会
影响HTML代码。
默认值为“true”
org.apache.myfaces.PRETTY_HTML
真的
org.apache.myfaces.DETECT\u JAVASCRIPT
假的
如果为true,则将呈现一个能够恢复
前垂直滚动每个请求。方便的功能,如果你有网页
对于长列表,您不希望浏览器页面总是跳转到顶部
如果您触发的链接或按钮操作保持在同一页面上。
默认值为“false”
org.apache.myfaces.AUTO_滚动
真的
面孔
org.apache.myfaces.webapp.MyFacesServlet
1.
上传servlet
controller.UploadServlet
面孔
*.jsf
面孔
*.面孔
上传servlet
/上传
org.apache.myfaces.webapp.StartupServletContextListener
错误: 类型状态报告

message/Graph/index.jsp

描述请求的资源 (/Graph/index.jsp)不可用


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

在那里你可以上传你的应用程序,它应该是开箱即用的
如果您不知道应该输入什么用户名和密码,那么必须配置tomcat users.xml,这不是问题。这是意料之中的行为。您只是误解了基本Servlet API的工作原理。您已经将JSF标准
FacesServlet
配置为侦听与
/faces/*
匹配的URL,并且已经将Apache MyFaces specific
MyFacesServlet
配置为侦听与
*.JSF
*.faces
匹配的URL

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

  • (调用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>

(在JSF2.0中,这已经不再需要了,使用默认的视图技术Facelets,可以将
FacesServlet
映射到
*.xhtml
,这与Facelets文件的默认扩展名相同)

tomcat文件夹结构是什么样子的,以及如何尝试调用JSP?在jsf应用程序中,必须使用.jsf文件扩展名调用它们。
<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>