Announcement Announcement Module
No announcement yet.
MVC and file uploaded Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • MVC and file uploaded

    I imagine it is easy :-) but I am not able to get the name of the file uploaded using MVC....I'm customizing the simple example of Chapter 13 and the example works.

    I have the following jsp page:
    <h3> Attachment:</h3>
    <spring:bind path="command.attachment">
    <input type="file" name='<c: out value="${status.expression}"/>'
    value='<c: out value="${status.value}"/>'

    and the Controller:
    protected ModelAndView onSubmit(
    HttpServletRequest request,
    HttpServletResponse response,
    Object command,
    BindException errors)
    //let's see if there's content there
    if(icr.getAttachment().length >0) {

    and also I registered the editor:
    protected void initBinder(HttpServletRequest request, ServletRequestDataBinder binder) throws ServletException {
    binder.registerCustomEditor(byte[].class, new ByteArrayMultipartFileEditor());

    Everything works fine and the file is converted in byte[] and saved in the database. Anyway I would like also to save the name of the file in the database accordingly to the name of the file uploaded by the user. How can I get such name?