@FormParam注释上的Java RESTful服务错误

@FormParam注释上的Java RESTful服务错误,rest,jersey,java-ee-6,glassfish-3,jdk1.7,Rest,Jersey,Java Ee 6,Glassfish 3,Jdk1.7,我正在用JavaEE6编写一个RESTful服务应用程序。我在定义使用@FormParam注释的HTTP GET服务方法时遇到了困难 我使用的技术: Eclipse EE开普勒IDE jdkv7 GlassFish3(基于Java6) 泽西岛(玻璃鱼的一部分) 爪哇: 你知道罪魁祸首是什么吗?你应该使用POST,而不是GET。使用GET,浏览器不会设置内容类型标题,因为参数是在URL中发送的,而不是在正文中发送的。如果您想将其与GET一起保存,请使用@QueryParam,它可以从URL中的

我正在用JavaEE6编写一个RESTful服务应用程序。我在定义使用@FormParam注释的HTTP GET服务方法时遇到了困难

我使用的技术:

  • Eclipse EE开普勒IDE
  • jdkv7
  • GlassFish3(基于Java6)
  • 泽西岛(玻璃鱼的一部分)
爪哇:


你知道罪魁祸首是什么吗?

你应该使用POST,而不是GET。使用GET,浏览器不会设置内容类型标题,因为参数是在URL中发送的,而不是在正文中发送的。如果您想将其与GET一起保存,请使用
@QueryParam
,它可以从URL中的查询字符串捕获参数,非常好;这是正确的答案
@GET
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Produces(MediaType.TEXT_HTML)
@Path("/getFromForm")
public String getFromForm(@FormParam("input") String input){
    log.log(Level.INFO, "Invoked getFromForm");
    String html = "<html> <body>"
            +"<center><h1> "+input+"</h1></center>"
            +"</body></html>";
    return html;
}
 <form action="/RESTfulServiceDrill/rest/v6/html/getFromForm" method="get" 

enctype="application/x-www-form-urlencoded">

<label> Add message: </label>
<input type="text" name="input"/>

<input type="submit" value="OK"/>
<input  type="reset" value="clear"/>

</form>
java.lang.IllegalStateException: The @FormParam is utilized when the content type of the request entity is not application/x-www-form-urlencoded