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: