Jersey2.x helloworl

Source: Internet
Author: User
Tags glassfish

Jersey has recently upgraded. Https://jersey.java.net/

Previously, 1.xwas used. The difference is quite big. The package changed from sun to glassfish.

Get down to the topic.

First, download jaxrs-ri-2.0.zip from the official website

Copy lib to the project classpath.

Then, configure web. xml

Web. xml

<!-- jersey rest begin --><servlet><servlet-name>jersey-serlvet</servlet-name><servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class><init-param>     <param-name>jersey.config.server.provider.packages</param-name>     <param-value>com.linpeng.ws.rest</param-value></init-param><load-on-startup>1</load-on-startup></servlet> <servlet-mapping><servlet-name>jersey-serlvet</servlet-name><url-pattern>/rest/*</url-pattern></servlet-mapping><!-- jersey rest end -->

Jersey. config. server. provider. Packages: scan the restws package directory

Noon. Java

package com.linpeng.ws.rest;import javax.ws.rs.GET;import javax.ws.rs.Path;import javax.ws.rs.PathParam;import javax.ws.rs.Produces;import javax.ws.rs.core.MediaType;@Path("/noon")public class Noon {@GET@Path("/{param}")@Produces(MediaType.TEXT_PLAIN)public String getMsg(@PathParam("param") String name) {String msg = "Rest say: good noon " + name;return msg;}}

Define a rest Service

You can access the service through/rest/noon/{yourname.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.