开发者

With Fields and File uploading

I have a form which contains fields and file upload elements while submitting the form it is throwing a null pointer exception, when i logged the form object all fields are getting null and when i am removing the form enctype="multipart/form-data"1 then i get all fields but the file object is getting null.

Form Code :

<form:form method="post" id="form" name="frm" action="${action}" enctype="multipart/form-data"> 
    <table>
        <tr>
            <td><form:label path="productName">Product Name: </form:label></td>
            <td>
              <form:input path="productName"/>
            </td>
        </tr>           

        <tr>
            <td><form:label path="rfile">Receipt File</form:label></td>
            <td><form:input path="rfile" id="receiptFile" type="file" /></td>
        </tr>           
        <tr>
            <td colspan="2"><input type="submit" value="Upload Receipt" /></td>
        </tr>
    </table>    
</form:form>

COntroller Code:

@RequestM开发者_JAVA技巧apping(value="/test.do", method = RequestMethod.POST)
public ModelAndView testReceipt(@ModelAttribute("frm") ReceiptForm form, BindingResult result, HttpServletRequest request){

    System.out.println("---"+form.getProductName());
    System.out.println("---"+form.getRfile());
}

Please note file is a type of: CommonsMultipartFile


Use FileUpload library to parse the request from the client.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜