JAVA Rest服装运动衫返回404

时间:2015-04-27 05:34:01

标签: java rest tomcat java-ee

您好我遵循了vogella教程,并根据我的要求进行了一些更改。当我在将应用程序部署到服务器后尝试调用服务时,我在休息客户端/浏览器中收到404(未找到)错误。请帮忙告诉我代码中有什么不对。

这是我的傻瓜

WEB.XML

<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
id="WebApp_ID" version="3.0">
<display-name>UploadDemo</display-name>
<servlet>
    <servlet-name>Jersey REST Service</servlet-name>
    <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
    <init-param>
        <param-name>com.sun.jersey.config.property.packages</param-name>
        <param-value>com.services.demo</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>Jersey REST Service</servlet-name>
    <url-pattern>/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<context-param>
    <description>Location to store uploaded file</description>
    <param-name>file-upload</param-name>
    <param-value>
     c:\data\
 </param-value>
</context-param>
</web-app>

Java Class

package com.services.demo;

import javax.ws.rs.GET;
import javax.ws.rs.Path;

@Path("/demo")
public class ServiceDemo {

@GET
@Path("/hello")
public String getMessage() {
    return "Hello world";
}


}

申请结构: Application structure

我调用的网址是

http://localhost:8080/uploadDemo/demo/hello

1 个答案:

答案 0 :(得分:2)

如果您没有在服务器端获得任何其他异常但仍然收到404错误,那么问题在于网址。

http://localhost:8080/uploadDemo/demo/hello

您的网址看起来不对,应该是:

http://localhost:8080/UploadDemo/demo/hello

我猜您在容器中部署的战争名称将是&#34; UploadDemo&#34; (通过查看您的文件夹结构)而不是&#34; uploadDemo&#34;