如果我从eclipse配置的tomcat执行此服务,我已经创建了一个Web服务,然后它正常工作
但如果我在没有eclipse tomcat(同样的tomcat但没有eclipse)的情况下执行此服务,则表示 415不支持的媒体类型
这是我的代码
@Path("{get}")
public class MyClass {
@POST
@Path("/token")
@Produces(MediaType.APPLICATION_JSON)
public Response getToken(@FormParam("username") String username, @FormParam("password") String password, @FormParam("identity") String identity){
System.out.println("Service called !!!");
if(username == null)
return Response.status(404).entity("username can not be null").build();
if(username != null && username.length() == 0)
return Response.status(404).entity("username can not be empty").build();
if(password == null)
return Response.status(404).entity("password can not be null").build();
if(password != null && password.length() == 0)
return Response.status(404).entity("password can not be empty").build();
if(identity == null)
return Response.status(404).entity("identity can not be null").build();
if(identity != null && identity.length() == 0)
return Response.status(404).entity("identity can not be empty").build();
OtherClass obj = new OtherClass();
return Response.status(200)
.entity(obj.getdata(username, password, identity))
.build();
}
web.xml是
<!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>Web Service</display-name>
<servlet>
<servlet-name>jersey-serlvet</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>com.sun.jersey.api.json.POJOMappingFeature</param-name>
<param-value>true</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>jersey-serlvet</servlet-name>
<url-pattern>/service/*</url-pattern>
</servlet-mapping>
</web-app>
通过chrome
从Advance Rest Client调用服务
请求中的内容类型是
text / html的