Servlet only supports GET and POST requests. In addition to GET and POST requests, restlet also supports DeletePutOPTIONS and other requests. Step 1: Compile the resource class (think of the Resource class as the Struts2 Action, and each method with the annotation is an ActionMethod) MovieResource. javapackagecom. zf. r
Servlet only supports GET and POST requests. In addition to GET and POST requests, restlet also supports Delete Put OPTIONS and other requests. Step 1: Compile the resource class (you can think of the Resource class as the Struts2 Action, and each method with the annotation is an ActionMethod) MovieResource. java package com. zf. r
Servlet only supports GET and POST requests.
In addition to GET and POST requests, restlet also supports Delete Put OPTIONS and other requests.
Step 1: Compile the resource class
(You can think of the Resource class as the Struts2 Action. Each method with the annotation is an ActionMethod)
MovieResource. java
Package com. zf. restlet. demo02.server; import org. restlet. resource. delete; import org. restlet. resource. get; import org. restlet. resource. post; import org. restlet. resource. put; import org. restlet. resource. serverResource;/*** take Method in 3 as an example * @ author zhoufeng **/public class MovieResource extends ServerResource {@ Getpublic String play () {return "the movie is playing... ";}@ Postpublic String pause () {return" movie pause... ";}@ Putpublic String upload () {return" the movie is being uploaded... ";}@ Deletepublic String deleteMovie () {return" deletes a movie... ";}}
Step 2: Use the html client for access (html only supports get and post access by default. So here are two examples)
Demo02.html
demo02
You can use two buttons to send different requests and return different values.
Step 3: Use Restlet to write client calls
MovieClient. java
Package com. zf. restlet. demo02.client; import java. io. IOException; import org. junit. test; import org. restlet. representation. representation; import org. restlet. resource. clientResource; public class MovieClient {@ Testpublic void test01 () throws IOException {ClientResource client = new ClientResource (" http://localhost:8888/ "); Representation result = client. get (); // call the get method System. out. println (result. getText () ;}@ Testpublic void test02 () throws IOException {ClientResource client = new ClientResource (" http://localhost:8888/ "); Representation result = client. post (null); // call the post method System. out. println (result. getText () ;}@ Testpublic void test03 () throws IOException {ClientResource client = new ClientResource (" http://localhost:8888/ "); Representation result = client. put (null); // call the put method System. out. println (result. getText () ;}@ Testpublic void test04 () throws IOException {ClientResource client = new ClientResource (" http://localhost:8888/ "); Representation result = client. delete (); // call the delete method System. out. println (result. getText ());}}