我正在用 Java EE 6 编写一个 RESTful 服务应用程序。我在定义使用 @FormParam 注释的 HTTP GET 服务方法时遇到了困难。
我使用的技术:
- Eclipse EE 开普勒 IDE
- JDK v7
- Glassfish 3(基于 Java 6)
- 泽西岛(Glassfish 的一部分)
爪哇:
@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;
}
JSP:
<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
任何想法的罪魁祸首是什么?