现在的位置: 首页 > 综合 > 正文

restful-post

2013年11月22日 ⁄ 综合 ⁄ 共 861字 ⁄ 字号 评论关闭

<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;
}
}

【上篇】
【下篇】

抱歉!评论已关闭.