0

我创建了 web 动态项目,上下文名称是“restJeresy”。并在我的本地使用 websphere 自由服务器。

当我点击 url http://localhost:9080/restJeresy/TestRestService/callService下面的错误显示

Error 404: Not Found 

谁能帮我我错过了什么?

这是我的代码,

package com.demo;

import javax.ws.rs.GET;
import javax.ws.rs.Path;

@Path("/TestRestService")
public class HelloWorldService {

     @Path("/callService")
     @GET
    public String getMsg() {
        return "Hello World !! - Jersey 2";
    }
}

Web.xml 文件

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
  <display-name>restJeresy</display-name>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>
  <servlet>
      <servlet-name>Jersey RESTful Application</servlet-name>
      <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
         <init-param>
            <param-name>jersey.config.server.provider.packages</param-name>
            <param-value>com.demo</param-value>
         </init-param>
         <load-on-startup>1</load-on-startup>
      </servlet>
   <servlet-mapping>
   <servlet-name>Jersey RESTful Application</servlet-name>
      <url-pattern>/</url-pattern>
   </servlet-mapping>  
</web-app>
4

1 回答 1

0

web.xml中servlet映射的问题。请检查

 <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0"> <display-name>restJeresy</display-name>

      <servlet>
          <servlet-name>Jersey RESTful Application</servlet-name>
          <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
               <init-param>
                <param-name>jersey.config.server.provider.packages</param-name>
                <param-value>com.demo</param-value>
            </init-param>
             <load-on-startup>1</load-on-startup>
          </servlet>    
<servlet-mapping>    
<servlet-name>Jersey RESTful Application</servlet-name>
          <url-pattern>/restf/*</url-pattern>    
</servlet-mapping>   
</web-app>

然后尝试访问http://localhost:9080/restJersey/restf/TestRestService/callService

于 2016-12-12T02:55:14.673 回答