Document directory
- Step 1: create a web service project;
- Step 2: Create a class
Myeclipse supports the rest service, which is very convenient for development. Here is an example of a computer:
Functions: addition, subtraction, multiplication, and Division;
The effect is as follows:
Key points of the rest service: each service or anything has a URI;
Step 1: create a web service project; Step 2: Create a class
Package Org. xiazdong. service; import javax. WS. rs. get; import javax. WS. rs. path; import javax. WS. rs. pathparam; import javax. WS. rs. produces; import COM. sun. jersey. SPI. resource. singleton; @ produces ("text/plain") @ path ("Calculator ") @ singletonpublic class myservice {@ get // sets this service as a GET request service @ path ("Add/{ID }") // firstrest/calculator/Add/1 + 1 Public String add (@ pathparam ("ID") string s) {string [] Ss = S. split ("\ +"); Return S + "=" + String. valueof (integer. parseint (ss [0]) + integer. parseint (ss [1]);} @ get @ path ("sub/{ID }") // firstrest/calculator/Add/1-1public string sub (@ pathparam ("ID") string s) {string [] Ss = S. split ("\-"); Return S + "=" + String. valueof (integer. parseint (ss [0])-integer. parseint (ss [1]);} @ get @ path ("Mult/{ID }") // firstrest/calculator/Add/1*1 Public String mult (@ pathparam ("ID") string s) {string [] Ss = S. split ("\ *"); R Eturn S + "=" + String. valueof (integer. parseint (ss [0]) * integer. parseint (ss [1]);} @ get @ path ("DIV/{ID}") // firstrest/calculator/Add/1 ~ 1 Public String Div (@ pathparam ("ID") string s) {string [] Ss = S. Split ("~ "); Return S +" = "+ String. valueof (integer. parseint (ss [0])/integer. parseint (ss [1]);}
@ Post // set this service as a POST request service @ path ("add") Public String add (@ formparam ("TT") string S) {// TT is the namestring [] Ss = s of textfield of the form. split ("\ +"); Return S + "=" + String. valueof (integer. parseint (ss [0]) + integer. parseint (ss [1]);}
Zookeeper ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
The difference between rest and RPC.
- Rest emphasizes that resources have unique Uris, while RPC is more powerful (verb) and is called by unified interfaces.
- Rest regression was originally designed for HTTP. RPC only uses HTTP as the transmission protocol.
- Rest is driven by hypertext; RPC is driven by methods.
- Rest emphasizes the semantic visibility of HTTP Communication, which is embodied by the message header and standard HTTP method. RPC encapsulates the semantics in the HTTP message body.