English 中文(简体)
HTTP 状态404 - Servlet JAX-RS 服务器不可用
原标题:HTTP Status 404 - Servlet JAX-RS Servlet is not available

我试图用日光节创建休息的网络服务,

http://shrikantuw.blogspot.in/2012/03/jersy-developing-restful-web-service.html" rel=“nofollow”

但当我试图跑进Tomcat 并击中

http://localhost:8080/RestFulWS/rest/exampleWithOutParam/getName

我正得到

HTTP 状态404 - Servlet JAX-RS 服务器不可用

我的Tomcat港口也只有8080个

请让我做我该做的事吧。

问题回答

如果您的 Web. xml 和服务类地图如下, 它应该正常工作 :

你的url:

http://localhost:8080/RestFulWS/rest/exampleWithOutParam/getName

Web.xml:

<display-name>RestFulWS</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.yourapp</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>Jersey REST Service</servlet-name>
    <url-pattern>/rest/*</url-pattern>
</servlet-mapping>

您的服务 :

package com.yourapp;
// imports here
@Path("/exampleWithOutParam")
public class YourService {
     @GET
     @Path("/getName")
     @Produces("text/plain")
     public Response getName() {
        return Response.ok("OK").build();
     }
}

确保球衣罐确实属于您的网络服务(即,在Tomcat中安装的网络服务包的WEB-INF/lib目录)。

     <display-name>RestFulWS</display-name>
     <servlet>
       <servlet-name>Jersey REST Service</servlet-name>
    <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servletclass>
      <init-param>
        <param-name>com.sun.jersey.config.property.packages</param-name>
       <param-value>com.yourapp</param-value>
     </init-param>
       <load-on-startup>1</load-on-startup>
   </servlet>
     <servlet-mapping>
          <servlet-name>Jersey REST Service</servlet-name>
          <url-pattern>/rest/*</url-pattern>
      </servlet-mapping>

您的 Web. xml 文件要像这样... 映射 serverlet 类和根资源类 。





相关问题
Tomcat´s server.xml dynamic configuration

My web application uses the same database configuration as the application XYZ. I have a resource declaration for a context in server.xml, so I have a duplicated configuration (once for web ...

session transfer issue from Tomcat to ASP.Net

I am using Tomcat to host JSP and using IIS 7.0 to host aspx (C# + .Net 3.5 + VSTS 2008), and I have some session transfer issue from JSP page to ASPX page. JSP page is in one domain and all other ...

JSP exception - class not found (tomcat)

I m setting up an existing application on a new Tomcat 5.5 server connecting to a Postgres database (running on Debian Lenny). When I access it I get a series of stack traces with the following root ...

热门标签