Main Tutorials

According to TLD, tag form:input must be empty, but is not

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

  1. Spring MVC view form handing

About Author

author image
Founder of Mkyong.com, love Java and open source stuff. Follow him on Twitter. If you like my tutorials, consider make a donation to these charities.

Comments

Subscribe
Notify of
1 Comment
Most Voted
Newest Oldest
Inline Feedbacks
View all comments
Dave Howes
8 years ago

There is another cause for this – if you forget to close the input tag you get exactly the same error. So, if you do

rather than

you’ll see the same error message