IntelliJ JSF基本项目在Tomcat

时间:2016-11-16 16:56:04

标签: java tomcat web-applications http-status-code-404

我使用Tomcat 9在IntelliJ IDEA中创建了一个新的JSF-PrimeFaces项目,它不起作用。

的index.xhtml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://xmlns.jcp.org/jsf/html"
      xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
      xmlns:f="http://xmlns.jcp.org/jsf/core"
      xmlns:p="http://primefaces.org/ui">
   <h:body>
      <h:form>
         <p:panel header="Keyboard Demo">
            <p:keyboard value="#{keyboardBean.value}"/>
         </p:panel>
         <p:commandButton value="Submit"/>
      </h:form>
   </h:body>
</html>

KeyBoardBean.java

package main;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

@ManagedBean
@SessionScoped
public class KeyBoardBean {

    private String value;

    public String getValue() {
        System.out.println("KeyboardBean::reading value: " +value);
        return value;
    }

    public void setValue(String value) {
        System.out.println("KeyboardBean::setting value: " +value);
        this.value = value;
    }
}

的web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
         version="3.1">

    <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>*.xhtml</url-pattern>
    </servlet-mapping>
</web-app>

当我运行Tomcat时,这就是我得到的:

Error 404

我错过了什么?我的IDEA安装坏了吗?

编辑:我尝试使用Tomcat 8,我使用Primefaces模板创建了一个新的默认项目,运行并出现上面相同的错误,这是服务器输出:

"C:\Program Files\Apache Software Foundation\apache-tomcat-8.5.8\bin\catalina.bat" run
Using CATALINA_BASE:   "C:\Users\Antonio\.IntelliJIdea2016.2\system\tomcat\Tomcat_8_5_8_untitled"
Using CATALINA_HOME:   "C:\Program Files\Apache Software Foundation\apache-tomcat-8.5.8"
Using CATALINA_TMPDIR: "C:\Program Files\Apache Software Foundation\apache-tomcat-8.5.8\temp"
Using JRE_HOME:        "C:\Program Files\Java\jdk1.8.0_111"
Using CLASSPATH:       "C:\Program Files\Apache Software Foundation\apache-tomcat-8.5.8\bin\bootstrap.jar;C:\Program Files\Apache Software Foundation\apache-tomcat-8.5.8\bin\tomcat-juli.jar"
17-Nov-2016 19:03:27.101 INFORMAZIONI [main] org.apache.catalina.startup.VersionLoggerListener.log Server version:        Apache Tomcat/8.5.8
17-Nov-2016 19:03:27.102 INFORMAZIONI [main] org.apache.catalina.startup.VersionLoggerListener.log Server built:          Nov 3 2016 21:14:13 UTC
17-Nov-2016 19:03:27.102 INFORMAZIONI [main] org.apache.catalina.startup.VersionLoggerListener.log Server number:         8.5.8.0
17-Nov-2016 19:03:27.102 INFORMAZIONI [main] org.apache.catalina.startup.VersionLoggerListener.log OS Name:               Windows 10
17-Nov-2016 19:03:27.103 INFORMAZIONI [main] org.apache.catalina.startup.VersionLoggerListener.log OS Version:            10.0
17-Nov-2016 19:03:27.103 INFORMAZIONI [main] org.apache.catalina.startup.VersionLoggerListener.log Architecture:          amd64
17-Nov-2016 19:03:27.103 INFORMAZIONI [main] org.apache.catalina.startup.VersionLoggerListener.log Java Home:             C:\Program Files\Java\jdk1.8.0_111\jre
17-Nov-2016 19:03:27.103 INFORMAZIONI [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Version:           1.8.0_111-b14
17-Nov-2016 19:03:27.103 INFORMAZIONI [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Vendor:            Oracle Corporation
17-Nov-2016 19:03:27.103 INFORMAZIONI [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_BASE:         C:\Users\Antonio\.IntelliJIdea2016.2\system\tomcat\Tomcat_8_5_8_untitled
17-Nov-2016 19:03:27.103 INFORMAZIONI [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_HOME:         C:\Program Files\Apache Software Foundation\apache-tomcat-8.5.8
17-Nov-2016 19:03:27.103 INFORMAZIONI [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcom.sun.management.jmxremote=
17-Nov-2016 19:03:27.104 INFORMAZIONI [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcom.sun.management.jmxremote.port=1099
17-Nov-2016 19:03:27.104 INFORMAZIONI [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcom.sun.management.jmxremote.ssl=false
17-Nov-2016 19:03:27.104 INFORMAZIONI [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcom.sun.management.jmxremote.authenticate=false
17-Nov-2016 19:03:27.104 INFORMAZIONI [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.rmi.server.hostname=127.0.0.1
17-Nov-2016 19:03:27.104 INFORMAZIONI [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djdk.tls.ephemeralDHKeySize=2048
17-Nov-2016 19:03:27.104 INFORMAZIONI [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.protocol.handler.pkgs=org.apache.catalina.webresources
17-Nov-2016 19:03:27.104 INFORMAZIONI [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.config.file=C:\Users\Antonio\.IntelliJIdea2016.2\system\tomcat\Tomcat_8_5_8_untitled\conf\logging.properties
17-Nov-2016 19:03:27.104 INFORMAZIONI [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
17-Nov-2016 19:03:27.104 INFORMAZIONI [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.base=C:\Users\Antonio\.IntelliJIdea2016.2\system\tomcat\Tomcat_8_5_8_untitled
17-Nov-2016 19:03:27.104 INFORMAZIONI [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.home=C:\Program Files\Apache Software Foundation\apache-tomcat-8.5.8
17-Nov-2016 19:03:27.104 INFORMAZIONI [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.io.tmpdir=C:\Program Files\Apache Software Foundation\apache-tomcat-8.5.8\temp
17-Nov-2016 19:03:27.104 INFORMAZIONI [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent Loaded APR based Apache Tomcat Native library 1.2.10 using APR version 1.5.2.
17-Nov-2016 19:03:27.104 INFORMAZIONI [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent APR capabilities: IPv6 [true], sendfile [true], accept filters [false], random [true].
17-Nov-2016 19:03:27.104 INFORMAZIONI [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent APR/OpenSSL configuration: useAprConnector [false], useOpenSSL [true]
17-Nov-2016 19:03:27.952 INFORMAZIONI [main] org.apache.catalina.core.AprLifecycleListener.initializeSSL OpenSSL successfully initialized (OpenSSL 1.0.2j  26 Sep 2016)
17-Nov-2016 19:03:28.016 INFORMAZIONI [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["http-nio-8080"]
17-Nov-2016 19:03:28.057 INFORMAZIONI [main] org.apache.tomcat.util.net.NioSelectorPool.getSharedSelector Using a shared selector for servlet write/read
17-Nov-2016 19:03:28.058 INFORMAZIONI [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["ajp-nio-8009"]
17-Nov-2016 19:03:28.059 INFORMAZIONI [main] org.apache.tomcat.util.net.NioSelectorPool.getSharedSelector Using a shared selector for servlet write/read
17-Nov-2016 19:03:28.059 INFORMAZIONI [main] org.apache.catalina.startup.Catalina.load Initialization processed in 1134 ms
17-Nov-2016 19:03:28.073 INFORMAZIONI [main] org.apache.catalina.core.StandardService.startInternal Starting service Catalina
17-Nov-2016 19:03:28.073 INFORMAZIONI [main] org.apache.catalina.core.StandardEngine.startInternal Starting Servlet Engine: Apache Tomcat/8.5.8
17-Nov-2016 19:03:28.079 INFORMAZIONI [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler [http-nio-8080]
17-Nov-2016 19:03:28.084 INFORMAZIONI [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler [ajp-nio-8009]
17-Nov-2016 19:03:28.086 INFORMAZIONI [main] org.apache.catalina.startup.Catalina.start Server startup in 26 ms
17-Nov-2016 19:03:38.080 INFORMAZIONI [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory C:\Program Files\Apache Software Foundation\apache-tomcat-8.5.8\webapps\manager
17-Nov-2016 19:03:38.267 INFORMAZIONI [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory C:\Program Files\Apache Software Foundation\apache-tomcat-8.5.8\webapps\manager has finished in 187 ms
[2016-11-17 07:03:54,997] Artifact untitled:war exploded: Server is not connected. Deploy is not available.
Connected to server
[2016-11-17 07:03:55,018] Artifact untitled:war exploded: Artifact is being deployed, please wait...
[2016-11-17 07:03:55,073] Artifact untitled:war exploded: Artifact is deployed successfully
[2016-11-17 07:03:55,074] Artifact untitled:war exploded: Deploy took 56 milliseconds

Project.rar

1 个答案:

答案 0 :(得分:0)

您应该指定Web应用程序的上下文根。 默认情况下,如果未指定,它将使用war的文件名,但如果由于版本更改而导致战争发生更改,则更改应用程序客户端的应用程序URL将很笨拙。因此,最佳做法是配置应用程序的上下文根。

而不是localhost:8080/index.html,它将是localhost:8080/yourApp/index.html

部署战争时,您应该在WAR的context.xml文件夹中存在META-INF文件。如果你的项目来源中有一个META-INF文件夹,它可以完成这项工作。
否则,你应该详细说明如何建立你的战争。

在此文件中,以这种方式指定作为根上下文的文档库:

<?xml version='1.0' encoding='utf-8'?>
<Context
  docBase="yourApp">
</Context>

来自official doc

  

在应用程序内的/META-INF/context.xml中的单个文件中   文件。可选(基于主机的copyXML属性),这可能是   复制到$ CATALINA_BASE / conf / [enginename] / [hostname] /并重命名为   应用程序的基本文件名加上“.xml”扩展名。

此外,不应要求在浏览器中指定index.html,因为其中一个默认欢迎文件页面为index.html