尝试访问 REST webapp 时出现 404 错误

I'm getting 404 error when trying to access REST webapp

我在 tomcat 6 中使用球衣 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>

这是网络服务 class:

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 时 returns 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

正如我在评论中提到的,您有以下错误:

  1. 对于 class Service 你的包名是 it.eng.ddd.webservice.salvaVotazioni 但在 web.xml 中你提到了 <param-value>it.eng.ddd.webservice</param-value>。而且,这就是我要求上传完整代码的原因(我看到有人犯同样的错误)
  2. 我不确定,你到底想在这里做什么

    @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)
    
  3. 从提供的日志来看,您似乎正在尝试访问 http://appurl:8080/ddd/rest,但您的实际端点应该是 http://appurl:8080/ddd/rest/SalvaVotazioni/salva/{codiceEnte}

这里有很好的教程,可以帮助你理解,如何使用@PathParam