我在雄猫 2.6 中使用球衣 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>
这是网络服务类:
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();
}
当我在火狐上调用 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
正如我在评论中提到的,您有以下错误:
- 对于类
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)
您在这里混合了所有内容,url ???? 中
PathParam
在哪里我认为,您正在尝试通过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