簡體   English   中英

騎行服api com.sun.jersey.api.container.ContainerExceptionServlet

[英]Jersey rest api com.sun.jersey.api.container.ContainerExceptionServlet

我是創建API的新手。 我發現我認為這是一個簡單的在線示例,但無法使其正常工作。 任何幫助或建議都很好。

這是我的web.xml文件

<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">

<display-name>Hello, World Application</display-name>
<description>
This is a simple web application with a source code organization
based on the recommendations of the Application Developer's Guide.
</description>

<servlet>
    <servlet-name>GetEDPInfo</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>mypackage</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
    <servlet-name>GetEDPInfo</servlet-name>
    <url-pattern>/GetEDPInfo</url-pattern>
</servlet-mapping>

這是我的Java示例GetEDPInfo.java

package mypackage;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.core.Response;

@Path("/GetEDPInfo")
public class GetEDPInfo {

@GET
@Path("/{param}")
public Response getMsg(@PathParam("param") String msg) {
String output = "Welcome"+ msg;
return Response.status(200).entity(output).build();
}

}

我下載了這些jar文件,並將它們放在我的WEB-INF / lib目錄中,如asm-3.1.jar,jersey-core-1.8.jar,jersey-server-1.8.jar不確定我是否需要更多,但是這些都是我看過的例子中使用的那些。

我使用以下命令編譯了Java文件:javac -source 1.7 -target 1.7 -bootclasspath /usr/java/jdk1.7.0_80/jre/lib/rt.jar cp。:/ var / lib / tomcat6 / webapps / sample / WEB-INF / lib目錄/球衣核-1.8:/var/lib/tomcat6/webapps/sample/WEB-INF/lib/jersey-server-1.8:在/ var / lib中/ tomcat6中/ webapps /下采樣/ WEB-INF / lib / asm-3.1 GetEDPInfo.java

那創建了我的類文件,沒有錯誤。

當我導航到http:// grv4:8080 / sample / GetEDPInfo時,我收到此消息...

HTTP Status 405 - Method Not Allowed

type Status report

message Method Not Allowed

description The specified HTTP method is not allowed for the requested resource (Method Not Allowed).

當我導航到http:// grv4:8080 / sample / GetEDPInfo / Jeeves時,我收到此消息...

HTTP Status 404 - /sample/GetEDPInfo/Jeeves

type Status report

message /sample/GetEDPInfo/Jeeves

description The requested resource (/sample/GetEDPInfo/Jeeves) is not available.

這是我修改的代碼...

package mypackage;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.Consumes;
import javax.ws.rs.core.MediaType;

@Path("/GetEDPInfo")
public class GetEDPInfo {

@GET
@Path("/{param}")
@Produces(MediaType.TEXT_PLAIN) @Consumes(MediaType.TEXT_PLAIN)
public String getMsg(@PathParam("param") String msg) {
String output = "Welcome"+ msg;
return output;
}

}

<param-value>mypackage.GetEDPInfo</param-value>更改為following,它應該可以工作<param-value>mypackage</param-value>

我能夠使其工作,由於某種原因,我需要更改我的web.xml文件以將/ *用作我的網址格式...

<servlet-mapping>
<servlet-name>GetEDPInfo</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM