![](/img/trans.png)
[英]Java web service “HTTP status 404” - Eclipse, Apache, Tomcat
[英]Java RESTfull web service with tomcat and eclipse gives 404
我见过很多人在这里问类似的问题,但是他们的解决方案都不适合我。 我正在尝试通过eclipse和tomcat创建REST服务,但我不断收到404页面。
我的Java课:
package com.audiencescience.rtbtools.requestvalidator.servlet;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
@Path("/bidChecker")
public class BidCheckerRESTService {
@GET
@Produces(MediaType.TEXT_HTML)
public Response testGet() {
return Response.status(200).entity("<html><head></head><body>Hello world</body></html>").build();
}
}
这是我的web.xml:
<web-app id="WebApp_ID" version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>Restful Web Application</display-name>
<servlet>
<servlet-name>jersey-serlvet</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.audiencescience.rtbtools.requestvalidator.servlet</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>jersey-serlvet</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
</web-app>
网址:
http://localhost:8080/BidCheckerWebService/bidchecker
返回404。我使用的是jersey-bundle 1.18
根据web.xml
的url-pattern
设置,您的Web服务URL应为http://localhost:8080/BidCheckerWebService/rest/bidChecker
即您需要在URL中包含/rest/
,并且上下文应与该URL匹配在@Path
指定。
您的rest servlet被映射到/rest/*
因此您的URL应如下所示:
http://localhost:8080/BidCheckerWebService/rest/bidchecker
您也可以将url-pattern更改为/ *,以使您当前的URL可以正常工作,即上述路径建议的路径中没有/ rest。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.