1

我正在尝试使用一个简单的 java web 服务。

web.xml 文件如下:

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

  <servlet>
    <display-name>JAX-RS REST Servlet</display-name>
    <servlet-name>JAX-RS REST Servlet</servlet-name>
    <servlet-class>
        com.sun.jersey.spi.container.servlet.ServletContainer
    </servlet-class>
    <load-on-startup>1</load-on-startup>
  </servlet>

  <servlet-mapping>
    <servlet-name>JAX-RS REST Servlet</servlet-name>
    <url-pattern>/services/*</url-pattern>
  </servlet-mapping>

  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
</web-app>

服务代码的a部分如下:

@Produces("application/xml")
@Path("/handles")
@Singleton
public class HandleService {

    File privateKeyFile;

    public HandleService(){
        privateKeyFile = new File("/Users/harsha/Desktop/admpriv.bin");
        //privateKeyFile = new File("/Users/cheny18/Documents/workspace/dcoHandleApplet/admpriv.bin");
    }

    @Produces("text/plain")

    @GET
    @Path("/test")
    public String returnTestString()
    {
        return "<p>this is for testing purpose only</p>";

    }

当我在本地机器上运行 Web 服务时,index.html 会正确加载。但是当我调用 localhost:8080/project_name/services/handles/test 时,我得到一个 404 resource not found 错误。

我哪里错了?

4

0 回答 0