Aleksandrs Rudzitis Aleksandrs Rudzitis - 29 days ago 10
Java Question

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

I try to create form in JSP and have one problem with input field.
Here is part of my JSP page:

<section>
<div class="container">
<h4>Add new PC or Laptop</h4>
<div class="form">
<form:form method="post" action="/app/pc/add" class="form-horizontal" modelAttribute="pc" role="form">
<div class="control-group">
<label class="control-label" for="number">PC Number</label>
<div class="controls">
<form:input id="number" placeholder="Number" path="number">
</div>
</div>
<div class="control-group">
<label class="control-label" for="cpu">CPU</label>
<div class="controls">
<form:input id="cpu" placeholder="CPU" path="cpu">
</div>
</div>
<div class="control-group">
<label class="control-label" for="hdd">HDD size</label>
<div class="controls">
<form:input id="hdd" placeholder="HDD size" path="hdd">
</div>
</div>
<div class="control-group">
<label class="control-label" for="os">OS</label>
<div class="controls">
<form:select id="os" path="os">
<c:forEach items="<%=com.springapp.mvc.entities.OpSystem.values()%>" var="value">
<option value="${value}">${value}</option>
</c:forEach>
</select>
</div>
</div>
<div class="control-group">
<label class="control-label" for="office">Office</label>
<div class="controls">
<form:input id="office" placeholder="Office version" path="office">
</div>
</div>
<div class="control-group">
<div class="controls">
<form:button type="submit" class="btn">Save</button>
</div>
</div>

</form>
</div>
</div>
</section>


And here is my Controller class:

package com.springapp.mvc.controllers;

import com.springapp.mvc.entities.ComputerRepository;
import com.springapp.mvc.entities.OpSystem;
import com.springapp.mvc.entities.Pc;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

/**
* Created by aleksandrs on 12/27/13.
*/
@Controller
@RequestMapping("/app")
public class AppController {
@Autowired
private ComputerRepository repository;

@RequestMapping("/")
public ModelAndView getIndex(){
ModelAndView model = new ModelAndView("index");
model.addObject("act","");
return model;
}

@RequestMapping(value = "/pc/list")
public ModelAndView getPCList(){
ModelAndView model = new ModelAndView("index");
model.addObject("act","devices");
model.addObject("include","pc_list");
model.addObject("list",repository.findAll());
return model;
}

@RequestMapping(value = "/pc/add", method = RequestMethod.GET)
public ModelAndView addPc(){
ModelAndView model = new ModelAndView("index");
model.addObject("include","pc_add");
model.addObject("act","devices");
model.addObject("osTypes", OpSystem.values());
return model;
}

@RequestMapping(value = "/pc/add", method = RequestMethod.POST)
public ModelAndView savePc(@ModelAttribute("pc") Pc pc, BindingResult result){
repository.save(pc);
return new ModelAndView("redirect:/app/pc/list");
}

}


And here is an Error:

SEVERE: Servlet.service() for servlet [mvc-dispatcher] in context with path [] threw exception [/WEB-INF/pages/pc_add.jsp (line: 19, column: 24) According to TLD, tag form:input must be empty, but is not] with root cause
org.apache.jasper.JasperException: /WEB-INF/pages/pc_add.jsp (line: 19, column: 24) According to TLD, tag form:input must be empty, but is not
at org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:42)
at org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:443)
at org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:133)
at org.apache.jasper.compiler.Parser.parseBody(Parser.java:1633)
at org.apache.jasper.compiler.Parser.parseOptionalBody(Parser.java:1002)
at org.apache.jasper.compiler.Parser.parseCustomTag(Parser.java:1274)
at org.apache.jasper.compiler.Parser.parseElements(Parser.java:1452)
at org.apache.jasper.compiler.Parser.parseBody(Parser.java:1664)
at org.apache.jasper.compiler.Parser.parseOptionalBody(Parser.java:1002)
at org.apache.jasper.compiler.Parser.parseCustomTag(Parser.java:1274)
at org.apache.jasper.compiler.Parser.parseElements(Parser.java:1452)
at org.apache.jasper.compiler.Parser.parse(Parser.java:138)
at org.apache.jasper.compiler.ParserController.doParse(ParserController.java:242)
at org.apache.jasper.compiler.ParserController.parse(ParserController.java:102)
at org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:198)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:373)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:353)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:340)
at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:646)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:357)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:749)
at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:605)
at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:544)
at org.apache.jasper.runtime.JspRuntimeLibrary.include(JspRuntimeLibrary.java:954)
at org.apache.jsp.WEB_002dINF.pages.index_jsp._jspx_meth_c_005fwhen_005f0(index_jsp.java:278)
at org.apache.jsp.WEB_002dINF.pages.index_jsp._jspx_meth_c_005fchoose_005f0(index_jsp.java:240)
at org.apache.jsp.WEB_002dINF.pages.index_jsp._jspService(index_jsp.java:179)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:749)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:487)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:412)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:339)
at org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:238)
at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:264)
at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1208)
at org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:992)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:939)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:915)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:811)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:796)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1023)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:744)


Where I have error? Or may be I forgot some dependency in POM file?

Answer

You forgot to close your input tags:

<form:input id="hdd" placeholder="HDD size" path="hdd">

should be

<form:input id="hdd" placeholder="HDD size" path="hdd" />

Also note that the following is invalid:

<form:button type="submit" class="btn">Save</button>

The closing tag (</button>) must match the opening tag (<form:button>)