我在tomcat 6中使用了jersey 2.6。我收到404错误:
web.xml
:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<display-name>ddd</display-name>
<!-- Dichiarazione delle servlet !-->
<servlet>
<servlet-name>jax-rs</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>it.eng.ddd.webservice</param-value>
</init-param>
<init-param>
<param-name>jersey.config.server.provider.classnames</param-name>
<param-value>org.glassfish.jersey.filter.LoggingFilter</param-value>
</init-param>
<!-- <init-param>
<param-name>javax.ws.rs.Application</param-name>
<param-value>it.eng.ddd.webservice.EpraxiApplication</param-value>
</init-param>-->
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>jax-rs</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
</web-app>
这是webservice类:
package it.eng.ddd.webservice.salvaVotazioni;
@Path("/SalvaVotazioni")
public class Service
{
@GET
@Path("/salva")
@Produces(MediaType.APPLICATION_XML)
//@Consumes(MediaType.MULTIPART_FORM_DATA)
public Response save(@PathParam("codiceEnte") String codiceEnte)
{
return Response.status(200).entity("").build();
}
当我在firefox上调用http://appurl:8080/ddd/rest时,它返回HTTP状态404 - 未找到。 tomcat日志跟踪这个:
INFO: 6 * Server has received a request on thread http-8080-1
6 > GET http://appurl:8080/ddd/rest
6 > accept: image/jpeg, image/gif, image/pjpeg, application/x-ms-application, application/xaml+xml, application/x-ms-xbap, */*
6 > accept-encoding: gzip, deflate
6 > accept-language: it-IT
6 > cache-control: no-cache
6 > connection: Keep-Alive
6 > cookie: JSESSIONID=97812A3F4563918431A0B8EDC43C4D2D
6 > dnt: 1
6 > host: appurl:8080
6 > user-agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; WOW64; Trident/7.0; SLCC2; .NET CLR 2.0.50727; .NET4.0C; .NET4.0E)
2-gen-2018 16.28.14 org.glassfish.jersey.filter.LoggingFilter log
INFO: 6 * Server responded with a response on thread http-8080-1
6 < 404
答案 0 :(得分:0)
正如我在评论中提到的,你有以下错误:
Service
,您的包名称为it.eng.ddd.webservice.salvaVotazioni
,但在web.xml
中,您提到了<param-value>it.eng.ddd.webservice</param-value>
。而且,这就是我要求上传完整代码的原因(我看到人们犯同样的错误)我不确定,你在这里尝试的是什么
@Path("/salva")
@Produces(MediaType.APPLICATION_XML)
public Response save(@PathParam("codiceEnte") String codiceEnte)
你在这里混合了所有内容,其中PathParam
在url ????
我想,你试图通过url传递一些数据,如果是这样的话,它应该是类似的东西
@Path("/salva/{codiceEnte}")
@Produces(MediaType.APPLICATION_XML)
public Response save(@PathParam("codiceEnte") String codiceEnte)
从提供的日志中,您似乎正在尝试访问http://appurl:8080/ddd/rest
,但您的实际终端应为http://appurl:8080/ddd/rest/SalvaVotazioni/salva/{codiceEnte}
这是一个很好的教程,可以帮助您理解,如何使用 @PathParam