使用 Jersey 读取表单数据
我正在开发一个网络应用程序,其中有一个类似的表单,
<form name="form" action="create-user" method="post">
<input name="accept" type="checkbox"><span>{{acceptLegalTerms}}</span><br>
<input type="submit" value="{{Continue}}" class="primary fright"/>
</form>
在服务器端,我们使用 Jersey(在 GAE 上)。这就是我试图用来读取 POST 值的东西
@POST
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Path("create-user")
public Response createUser(@FormDataParam("accept") boolean acceptForm) {
return Response.ok().entity(acceptForm).build();
}
,但它不起作用...它返回给我...
HTTP ERROR 415
Problem accessing /login/create-user. Reason:
Unsupported Media Type
有什么想法吗?我做错了什么?
谢谢!
I'm developing a web app where i have a form like that
<form name="form" action="create-user" method="post">
<input name="accept" type="checkbox"><span>{{acceptLegalTerms}}</span><br>
<input type="submit" value="{{Continue}}" class="primary fright"/>
</form>
On the server side, We're using Jersey (on GAE). And here's what I'm trying to use to read the POST values
@POST
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Path("create-user")
public Response createUser(@FormDataParam("accept") boolean acceptForm) {
return Response.ok().entity(acceptForm).build();
}
But it doesn't work... It returns me...
HTTP ERROR 415
Problem accessing /login/create-user. Reason:
Unsupported Media Type
Any ideas? What Am I doing wrong?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
试试这个:
Multipart 略有不同,请参阅 jersey 示例 multipart-webapp 或参阅 http:// www.w3.org/Protocols/rfc1341/7_2_Multipart.html。您的 Web 表单未生成它,因此 Jersey 正确返回 415 - 不支持的媒体类型,因为您没有任何处理“application/x-www-form-urlencoded”媒体类型的资源。
try this:
Multipart is something slightly different, see jersey sample multipart-webapp or see http://www.w3.org/Protocols/rfc1341/7_2_Multipart.html. Your web form is not producing it, so Jersey correctly returns 415 - Unsupported media type, because you don't have any resource which is handling "application/x-www-form-urlencoded" media type.
为了简单起见:如果它是映射到特定 URL(在这种情况下为“测试”)的唯一请求处理程序,并且使用特定的 HTTP 方法 (POST),您可以避免使用 @Consumes!
Just to keep it simple: in case it is the only request handler mapped to the specific URL (in that case "test") and with the specific HTTP method (POST), you can avoid the usage of @Consumes!