According to TLD, tag form:input must be empty, but is not
By:Roy.LiuLast updated:2019-08-18
Problem
Developing a search form with the Spring MVC framework.
/WEB-INF/pages/tools/webserver.jsp – Spring mvc + form tag
<form:form method="post" commandName="searchForm" action="${pageContext.request.contextPath}/tools/webserver/" class="navbar-form pull-left" id="search-form"> Type a website : <form:input path="domainName" type="text" width="165px" placeholder="example - google.com" /> <button type="submit" class="btn btn-top-margin">Search</button> </form:form>
Spring Controller
@Controller @RequestMapping(value = "/tools", method = RequestMethod.GET) public class ToolsController { @RequestMapping(value = "/webserver", method = RequestMethod.GET) public ModelAndView main() { ModelAndView modelandView = new ModelAndView("tools/webserver", "searchForm", ""); return modelandView;
When access the page, it shows following error message.
org.apache.jasper.JasperException: /WEB-INF/pages/tools/webserver.jsp(41,5) According to TLD, tag form:input must be empty, but is not org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:40) org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:407) org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:132) org.apache.jasper.compiler.Parser.parseBody(Parser.java:1603) org.apache.jasper.compiler.Parser.parseOptionalBody(Parser.java:978) org.apache.jasper.compiler.Parser.parseCustomTag(Parser.java:1246) org.apache.jasper.compiler.Parser.parseElements(Parser.java:1422) org.apache.jasper.compiler.Parser.parseBody(Parser.java:1634) org.apache.jasper.compiler.Parser.parseOptionalBody(Parser.java:978) org.apache.jasper.compiler.Parser.parseCustomTag(Parser.java:1246) org.apache.jasper.compiler.Parser.parseElements(Parser.java:1422) org.apache.jasper.compiler.Parser.parse(Parser.java:130) org.apache.jasper.compiler.ParserController.doParse(ParserController.java:255) org.apache.jasper.compiler.ParserController.parse(ParserController.java:103) org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:185) org.apache.jasper.compiler.Compiler.compile(Compiler.java:354)
Solution
The message is misleading, actually, it means the form:input, domainName is empty, you need to link it with a field. To fix it, just create an object with domainName and link it via @Controller class.
public class SearchQuery { private String domainName; public String getDomainName() { return domainName; public void setDomainName(String domainName) { this.domainName = domainName;
Spring Controller
@Controller @RequestMapping(value = "/tools", method = RequestMethod.GET) public class ToolsController { @RequestMapping(value = "/webserver", method = RequestMethod.GET) public ModelAndView main() { ModelAndView modelandView = new ModelAndView("tools/webserver", "searchForm", new SearchQuery()); return modelandView;
Reference
From:一号门
COMMENTS