我在JSP中开发一个站点,但我的代码中有一些错误。 请帮我解决以下错误:
org.apache.jasper.JasperException: An exception occurred processing JSP page/WEBINF/jsp/Invoice.jsp at line 165
162: <table>
163: <tr>
164: <td>Invoice No :</td>
165: <td><form:input path="invoiceno" /></td>
166: <td>Sr No:</td>
167: <td><form:input path="srno" /></td>
168: </tr>
root cause
java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'MetalBean' available as request attribute
org.springframework.web.servlet.support.BindStatus.<init>(BindStatus.java:141)
org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getBindStatus(AbstractDataBoundFormElementTag.java:179)
org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getPropertyPath(AbstractDataBoundFormElementTag.java:199)
org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getName(AbstractDataBoundFormElementTag.java:165)
org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.autogenerateId(AbstractDataBoundFormElementTag.java:152)
org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.resolveId(AbstractDataBoundFormElementTag.java:143)
org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.writeDefaultAttributes(AbstractDataBoundFormElementTag.java:127)
org.springframework.web.servlet.tags.form.AbstractHtmlElementTag.writeDefaultAttributes(AbstractHtmlElementTag.java:421)
org.springframework.web.servlet.tags.form.InputTag.writeTagContent(InputTag.java:142)
org.springframework.web.servlet.tags.form.AbstractFormTag.doStartTagInternal(AbstractFormTag.java:103)
org.springframework.web.servlet.tags.RequestContextAwareTag.doStartTag(RequestContextAwareTag.java:80)
org.apache.jsp.WEB_002dINF.jsp.Invoice_jsp._jspx_meth_form_005finput_005f17(Invoice_jsp.java:1005)
org.apache.jsp.WEB_002dINF.jsp.Invoice_jsp._jspx_meth_form_005fform_005f1(Invoice_jsp.java:895)
org.apache.jsp.WEB_002dINF.jsp.Invoice_jsp._jspService(Invoice_jsp.java:116)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:723)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:388)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:723)
org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:238)
org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:264)
org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:12
我已将bean类创建为MetalBean
我的jsp文件是......
<form:form method="post" action="/insertMetalTransaction" modelAttribute="MetalBean">
<table>
<tr>
<td>Invoice No :</td>
<td><form:input path="invoiceNo" /></td>
<td>Sr No:</td>
<td><form:input path="srno" /></td>
</tr>
<tr>
<td>Date :</td>
<td><form:input path="date" /></td>
<td>Transaction Type :</td>
<td><form:input path="transactionType" /></td>
</tr>
<tr>
<td>Weight :</td>
<td><form:input path="weight" /></td>
<td>Tunch :</td>
<td><form:input path="tunch" /></td>
</tr>
<tr>
<td>Fine :</td>
<td><form:input path="fine" /></td>
<td>Certificate No :</td>
<td><form:input path="certificateNo" /></td>
</tr>
<tr>
<td>Sale Type :</td>
<td><form:input path="saleType" /></td>
</tr>
<tr>
<td> </td>
<td><input type="submit" value="Insert" /></td>
</tr>
</table>
<!-- Here is the Table -->
<table border="1">
<tr>
<td class="heading">Invoice No.</td>
<td class="heading">Sr No.</td>
<td class="heading">Date</td>
<td class="heading">Transaction Type</td>
<td class="heading">Weight</td>
<td class="heading">Tunch</td>
<td class="heading">Fine</td>
<td class="heading">Certificate No</td>
<td class="heading">Sale Type</td>
<td class="heading">Edit</td>
<td class="heading">Delete</td>
</tr>
<c:forEach var="in" items="${map.metalList}">
<tr id="${in.invoiceNo}">
<td>${in.invoiceNo}</td>
<td>${in.srno}</td>
<td>${in.date}</td>
<td>${in.transactionType}</td>
<td>${in.weight}</td>
<td>${in.tunch}</td>
<td>${in.fine}</td>
<td>${in.certificateNo}</td>
<td>${in.saleType}</td>
<td><a id="edit-${in.invoiceNo}" onclick='edit(this)' href="#" >Edit</a></td>
<td><a href="invoicedelete?id=${in.invoiceNo}">Delete</a></td>
</tr>
</c:forEach>
</table>
我的控制器类......
//////////////For Main Page//////////////////////////////////////////////////////////
@RequestMapping("/getList")
public ModelAndView getUserLIst() {
List<usercreation> userList = ucDaoImpl.getUserList();
return new ModelAndView("userList", "userList", userList);
}
@RequestMapping("/Invoice")
public ModelAndView loginUser1(Model model) {
model.addAttribute("InvoiceBean", new InvoiceBean());
Map<String, Object> map = new HashMap<String, Object>();
List<InvoiceBean> invoiceList = iDaoImpl.getInvoiceBeans();
map.put("invoiceList",invoiceList);
System.out.println(invoiceList);
List<MetalBean> metalList = mDaoImpl.getMetalBeans();
map.put("metalList",metalList);
System.out.println(metalList);
return new ModelAndView("Invoice","map",map);
}
答案 0 :(得分:0)
您将表单绑定到模型属性MetalBean
,但在向/Invoice
发出请求时,这不可用。此时只有InvoiceBean
可用。
修改控制器方法并在模型中设置MetalBean
。
@RequestMapping("/Invoice")
public ModelAndView loginUser1(Model model) {
model.addAttribute("MetalBean", new MetalBean());
...