(二)glassFish提供的rest接口的post方法

来源:互联网 发布:匿名四轴飞控源码 编辑:程序博客网 时间:2024/06/05 19:13

今天接着写,我们这次主要介绍post的接口编写,其实和上次差不多,还是贴代码吧

@Path("/test")//访问请求的路径组成部分
@Scope(value="request")//保证请求为单例
@Component//spring保证被初始化
public class MyRest {
@POST//只支持post请求拉
@Path("/name")//方法级别的请求路径拉
@Produces(MediaType.APPLICATION_JSON)//返回json字符串啦
public Response myTest(@FormParam("msg") String msg){//这的@FormParam不同于get请求的@QueryParam,下面贴一个html代码大家就会明白了
System.out.println(msg);
return Response.status(200).entity("张三").build();
}
}


下面再贴一个html代码

<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>测试</title>
</head>
<body>
<form action="http://localhost:8080/MyWeb/platform/test/name" method="post">我们的工程依旧叫MyWeb了
<input type="text" name="msg"/>
<input type="submit" value="提交"/>
</form>
</body>
</html>

0 0
原创粉丝点击