restful-post

<form action="http://localhost:8888/hello/count" method="post">
<input type="text" name="num"/>
<input type="submit" value="submit"/>

</form>


import javax.ws.rs.Consumes;
import javax.ws.rs.FormParam;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;


@Path("/hello")
public class HelloService {
private String count ;
@GET 
    @Produces("text/plain")
public String helloWorld(){
return "Hello world!";
}

@POST
@Path("sayhi")
@Consumes("application/x-www-form-urlencoded")
public String sayHello(@FormParam("msg")String name){
System.out.println("==============");
return "Hello "+name;
}
@POST
@Path("/count")
@Consumes("application/x-www-form-urlencoded")
public String counter(@FormParam("num")String num){
this.count = num;
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println(count);
return count;
}
}

你可能感兴趣的:(restful-post)