JSP
<%@ page language= "java" import= "java.util.*" pageencoding= "UTF-8"%> <% String Path = Request.getcontextpath ()
;
String basepath = request.getscheme () + "://" +request.getservername () + ":" +request.getserverport () +path+ "/"; %>
Package org.nercita.zmx;
Import Org.codehaus.jackson.jaxrs.JacksonJsonProvider;
Import Org.glassfish.jersey.server.ResourceConfig;
public class Restapplication extends ResourceConfig {public
restapplication () {
//service class is in the package path
packages (" Org.nercita.zmx ");
Register JSON Converter
register (jacksonjsonprovider.class);
}
Xml
<?xml version= "1.0" encoding= "UTF-8"?> <!--this web.xml the ' not ' required when using Servlet 3.0 container, Implementation Details http://jersey.java.net/nonav/documentation/latest/jax-rs.html--> <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" > < servlet> <servlet-name>jersey Web application</servlet-name> <servlet-class>org.glass fish.jersey.servlet.servletcontainer</servlet-class> <!--<init-param> <PARAM-NAME&G T;jersey.config.server.provider.packages</param-name> <param-value>org.nercita.zmx</param-value > </init-param>--> <init-param> <param-name>javax.ws.rs.application </param-name> <PARAM-VALUE>org.nercita.zmx.restapplication</param-value> </init-param> <LOAD-ON-STARTUP&G t;1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>jersey Web applic ation</servlet-name> <url-pattern>/webapi/*</url-pattern> </servlet-mapping> </web-
App>
Pom.xml
<project xmlns= "http://maven.apache.org/POM/4.0.0" xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance" xsi:s chemalocation= "http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd" > <modelversion >4.0.0</modelVersion> <groupId>org.nercita.ltxx</groupId> <artifactid>restdemo</ar tifactid> <packaging>war</packaging> <version>0.0.1-SNAPSHOT</version> <name>
restdemo</name> <build> <finalName>RestDemo</finalName> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifact Id>maven-compiler-plugin</artifactid> <version>2.5.1</version> <in Herited>true</inherited> <configuration> <SOURCE>1.7</SOURCE&G
T <target>1.7</target> </configuration> </plugin> </plugins> &
lt;/build> <dependencyManagement> <dependencies> <dependency>
<groupId>org.glassfish.jersey</groupId> <artifactId>jersey-bom</artifactId>
<version>${jersey.version}</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencymanagem ent> <dependencies> <dependency> <groupid>org.glassfish.jersey.cont Ainers</groupid> <artifactId>jersey-container-servlet-core</artifactId> <!-- Use the following artifactid if you don ' t need servlet 2.x compatibility--> <!--artifactid>jersey-c Ontainer-servlet</artIfactid--> </dependency> <!--uncomment this to get JSON support <depende Ncy> <groupId>org.glassfish.jersey.media</groupId> <artifactid>jersey-media-m Oxy</artifactid> </dependency>--> <!--Jackson JSON support--> <DEPENDENCY&G
T <groupId>org.codehaus.jackson</groupId> <artifactId>jackson-core-asl</artifactId> < version>1.9.12</version> </dependency> <dependency> <groupId>org.codehaus.jackson< /groupid> <artifactId>jackson-mapper-asl</artifactId> <version>1.9.12</version> & lt;/dependency> <dependency> <groupId>org.codehaus.jackson</groupId> <artifactId> jackson-jaxrs</artifactid> <version>1.9.12</version> </dependency> </dependen Cies> <properties> <jersey.version>2.22.2</jersey.version> <project.build.sourceencoding>u
Tf-8</project.build.sourceencoding> </properties> </project>