gpt4 book ai didi

java - IntelliJ JSF 基本项目在 Tomcat 中不起作用

转载 作者:行者123 更新时间:2023-11-28 23:23:04 28 4
gpt4 key购买 nike

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

索引.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;
}
}

网络.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

最佳答案

您应该指定您的网络应用程序的上下文根。默认情况下,如果未指定,它会使用 war 的文件名,但如果您的 war 由于版本更改而更改,则更改应用程序客户端的应用程序 url 是笨拙的。因此,最佳做法是配置应用程序的上下文根。

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

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

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

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

来自official doc :

In an individual file at /META-INF/context.xml inside the application files. Optionally (based on the Host's copyXML attribute) this may be copied to $CATALINA_BASE/conf/[enginename]/[hostname]/ and renamed to application's base file name plus a ".xml" extension.

此外,不需要在浏览器中指定 index.html,因为默认的欢迎文件页面之一是 index.html

关于java - IntelliJ JSF 基本项目在 Tomcat 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40637871/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com