简体   繁体   中英

org.apache.jasper.JasperException Error in code

I am developing a site in JSP, but I have some errors in my code. Please help me with the following error:

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

I have created the bean class as MetalBean

my jsp file is...

<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>&nbsp;</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>

My Controller class...

//////////////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);
}

You're binding your form to the model attribute MetalBean , but this is not available when a request to /Invoice is made. Only an InvoiceBean is available at that point.

Modify your controller method and set the MetalBean in the model.

@RequestMapping("/Invoice")
public ModelAndView loginUser1(Model model) {

    model.addAttribute("MetalBean", new MetalBean());

...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM