use*_*269 26 java parameters rest post jax-rs
我正在使用Jersey开发RESTful服务,它可以很好地处理GET方法.但我只能null使用该POST方法获取参数.这是我项目的示例代码.
<form action="rest/console/sendemail" method="post">
<input type="text" id="email" name="email">
<button type="submit">Send</button>
</form>
Run Code Online (Sandbox Code Playgroud)
@POST
@Path("/sendemail")
public Response sendEmail(@QueryParam("email") String email) {
System.out.println(email);
return new Response();
}
Run Code Online (Sandbox Code Playgroud)
我从帖子收到的电子邮件始终为空.有人有想法吗?
我将QueryParam更改为FormParam,我得到的参数仍为null.
小智 36
在通过提交一个表单POST,email是不是一个@QueryParam像/sendemail?email=me@example.com.
如果您form通过提交HTML POST,email则是@FormParam.
编辑:
这是一个可以处理HTML表单的最小JAX-RS资源.
package rest;
import javax.ws.rs.FormParam;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
@Path("/console")
public class Console {
@POST
@Path("/sendemail")
@Produces(MediaType.TEXT_PLAIN)
public Response sendEmail(@FormParam("email") String email) {
System.out.println(email);
return Response.ok("email=" + email).build();
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
50731 次 |
| 最近记录: |