Jax-rs (Java API for RESTful Web Services) One of the practical tutorials-exploring Jax-rs__java

Source: Internet
Author: User

Reprint please indicate the source http://blog.csdn.net/exsuns


Jsr-rs (Java API for RESTful Web Services) is a set of specifications that Sun releases for rest (jsr311)

On the concept of rest, we can search the Internet

A section from a wiki: REST observes the entire network from a resource perspective, and the distributed resources are determined by the URI, and the client's application takes the form of the resource through the URI. Getting these forms causes these applications to change their state. With the constant acquisition of the resources of the form, the client application is constantly changing its state, the so-called Phenotypic state transition (representational states Transfer).

Let's look at the bottom and see what it looks like.

Environment: myeclipse8.0m1/jdk1.6

1. New WebService Project->

Select Rest (Jax-rs) point "finish" in the frame of the pop-up settings window

2. New

After you complete the previous step, add a rest service

New->web Service

Fill in the service path, package name, class name and then click Add to add a service

Method Name: Methods Name of Class

Return type: Returning value type

HTTP Method:get/post/put/delete/head

URL Path: Service Name

Method parameters can set a list of methods parameters

Default value: If this parameter is not included in the request, it defaults to this value

Click Finish

Deploy to Tomcat

Execute Http://localhost:8080/rest/helloWorld/sayHi?name=exsun

The browser will return the result

Or use JavaScript to request:

var req; Creatreq (); function Creatreq () {var url = ' Http://localhost:8080/rest/helloWorld/sayHi?name=exsun '; if (window. XMLHttpRequest) {req = new XMLHttpRequest ();} else if (window. ActiveXObject) {req = new ActiveXObject ("Microsoft.XMLHTTP");} if (req) {Req.open ("get", url, true); Req.onreadystatech Ange = callback; Req.send (NULL); } function callback () {alert (req.responsetext);}

Execution results:


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.