restful-post

转载 2012年03月30日 14:40:58
<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
举报原因:
原因补充:

(最多只允许输入30个字)