Java 使用Jersey读取表单数据
我正在开发一个web应用程序,我有一个这样的表单Java 使用Jersey读取表单数据,java,google-app-engine,jersey,Java,Google App Engine,Jersey,我正在开发一个web应用程序,我有一个这样的表单 <form name="form" action="create-user" method="post"> <input name="accept" type="checkbox"><span>{{acceptLegalTerms}}</span><br> <input type="submit" value="{{Continue}}" class="primary
<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>
但它不起作用。。。它还我
HTTP ERROR 415
Problem accessing /login/create-user. Reason:
Unsupported Media Type
有什么想法吗?我做错了什么
谢谢 试试这个:
@Path("test")
@POST
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
public String testForm(@FormParam("accept") String accept) {
return accept;
}
Multipart略有不同,请参阅jersey示例Multipart webapp或参阅。您的web表单没有生成它,因此Jersey正确地返回415-不支持的媒体类型,因为您没有任何资源来处理“application/x-www-form-urlencoded”媒体类型。只是为了简单起见:如果它是唯一映射到特定URL(在这种情况下为“test”)和特定HTTP方法的请求处理程序(POST),您还需要避免使用@Consumes!。@DrewStephens是否可以使用一个路径同时为urlencode或多部分POST请求提供服务?是否有一种方法可以提交包含10个字段的表单,但不必添加10个
@FormParam
lines@VukStanković:
@Path("test")
@POST
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
public String testForm(@FormParam("accept") String accept) {
return accept;
}