404在一个简单的Jetty/Maven Hello World Web应用程序中找不到错误
我按照EclipseWiki上的说明创建了“带Jetty和Maven的标准WebApp”: 但是,当我运行webapp(mvnjetty:run)并转到localhost:8080/hello-world/hello时,我最终遇到了“HTTP错误404访问/hello-world/hello.Reason:找不到问题”。我阅读了文档,查看了wiki页面的历史,浏览了其他论坛和stackoverflow线程,但找不到这个看似简单问题的答案。我将发布我的源代码,但它与教程完全相同 任何帮助都将不胜感激。我真的很想开始玩这项技术,但它令人沮丧的是,继续砰地撞到同一个死胡同 (请注意:创建“JettyMavenHelloWorld”的教程的第一部分工作正常。我的问题是第二部分“JettyMavenHelloWarApp”。这一部分的标题是“使用Jetty和Maven开发标准WebApp”) JettyAvenhellowarapp/pom.xml404在一个简单的Jetty/Maven Hello World Web应用程序中找不到错误,maven,maven-2,jetty,embedded-jetty,Maven,Maven 2,Jetty,Embedded Jetty,我按照EclipseWiki上的说明创建了“带Jetty和Maven的标准WebApp”: 但是,当我运行webapp(mvnjetty:run)并转到localhost:8080/hello-world/hello时,我最终遇到了“HTTP错误404访问/hello-world/hello.Reason:找不到问题”。我阅读了文档,查看了wiki页面的历史,浏览了其他论坛和stackoverflow线程,但找不到这个看似简单问题的答案。我将发布我的源代码,但它与教程完全相同 任何帮助都将不胜感
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>hello-world</artifactId>
<version>0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Jetty HelloWorld</name>
<properties>
<jettyVersion>7.2.0.v20101020</jettyVersion>
</properties>
<dependencies>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
<version>${jettyVersion}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<!-- This plugin is needed for the servlet example -->
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>${jettyVersion}</version>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.1</version>
<executions>
<execution><goals><goal>java</goal></goals></execution>
</executions>
<configuration>
<mainClass>org.example.HelloWorld</mainClass>
</configuration>
</plugin>
</plugins>
</build>
</project>
4.0.0
org.example
教程给出的url不正确-您的应用程序上下文仍然是“/”,
因此URL是http://localhost:8080
和http://localhost:8080/hello
分别用于静态和动态内容
maven jetty插件文档确实声称默认上下文的名称将与pom.xml中的artifactId相同,但在这里似乎不起作用。我认为在pom中向jetty插件定义添加配置应该将contextpath更改为hello world:
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>${jettyVersion}</version>
<configuration>
<webApp>
<contextPath>/hello-world</contextPath>
</webApp>
</configuration>
</plugin>
org.eclipse.jetty
配置选项。我遇到了同样的问题,对我有效的方法是访问应用程序,比如:http://localhost:8080/hello/index.jsp
或http://localhost:8080/hello/index.html
,无论您使用的是html还是js页面。我的基本配置也有同样的问题
我想用Spring3MVC重定向这个配置的错误页面(在web.xml中)
404
/WEB-INF/views/error.html
我通过将error.html的扩展名更改为error.jsp来解决这个问题,我认为您在mvn jetty:run
之前没有运行mvn package
任务,这就是jetty没有看到任何源代码的原因。只需先运行mvn包。您的servlet映射不正确或不足
<url-pattern>/hello/*</url-pattern> // does not respond to "/hello"
/hello/*//不响应“/hello”
您需要为URL模式“/hello”添加映射
你好
<h1>Hello World Webapp</h1>
<a href="/hello">Hello Servlet</a>
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>${jettyVersion}</version>
<configuration>
<webApp>
<contextPath>/hello-world</contextPath>
</webApp>
</configuration>
</plugin>
<error-page>
<error-code>404</error-code>
<location>/WEB-INF/views/error.html</location>
</error-page>
<url-pattern>/hello/*</url-pattern> // does not respond to "/hello"
<url-pattern>/hello</url-pattern>