Jersey restful is an open-source and stable Java framework that implements JAX-RS specifications to support JAX-RS APIs, developers love it because of its stable, efficient, and convenient features. With continuous updates and improvements, jeysey's latest version is 2.6. however. version X and 1. version X differs greatly, 2. version X has some problems with some components in terms of compatibility and configuration. version X is still the main force in the market. Therefore, the hellorestful version of jersey1.x is the main content of this article.
The running environment is as follows:
JDK 1.7
Tomcat 8
Jersey 1.18
Eclipse Kepler
Steps:
1. Download Jersey 1.18 from the official jersey website.
2. Create a dynamic web project in eclipse and enter "hellorestworld" in the project ".
650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M02/4D/6C/wKiom1RQ8g-RWuxQAAN1V-vHMiw881.jpg "Title =" hellorestful.png "alt =" wKiom1RQ8g-RWuxQAAN1V-vHMiw881.jpg "/>
3. Unzip Jersey 1.18.zip downloaded in step 1 and copy the jar files under Jersey-archive-1.18 \ Lib to the/hellorestworld/webcontent/WEB-INF/lib directory.
4. Create helloworld. Java with the following code:
package com.favccxx.favrestful;import javax.ws.rs.GET;import javax.ws.rs.Path;import javax.ws.rs.Produces;import javax.ws.rs.core.MediaType;@Path("/hello")public class HelloWorld {@GET@Produces(MediaType.TEXT_PLAIN)public String getIt() {return "Welcome to Jeysey Hello World!";}}
5. modify web. xml and configure Jersey forwarding.
<?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>HelloRestWorld</display-name><servlet><servlet-name>JerseyRESTService</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>com.favccxx.favrestful</param-value></init-param><load-on-startup>1</load-on-startup></servlet><servlet-mapping><servlet-name>JerseyRESTService</servlet-name><url-pattern>/rest/*</url-pattern></servlet-mapping><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></web-app>
6. start Tomcat and enter http: // localhost: 8080/hellorestworld/rest/hello in the browser.
650) This. length = 650; "src =" http://s3.51cto.com/wyfs02/M02/4D/6C/wKioL1RQ8nmRA-7bAACZRdeA2uI203.jpg "Title =" hellojersey.png "width =" 660 "Height =" 64 "border =" 0 "hspace =" 0 "vspace =" 0 "style =" Width: 660px; Height: 64px; "alt =" wKioL1RQ8nmRA-7bAACZRdeA2uI203.jpg "/>
This article from the "dust wind with the shadows of the Sky" blog, please be sure to keep this source http://favccxx.blog.51cto.com/2890523/1569417
Jersey 1. x implements hellorestful