0

I'm trying to upload a file using jQuery .click().I'm getting only file name when I do request.getParameter() in my controller. Further I cant read that file with only file name. But when I use action to my form I will get the object of the file. But I don't want to use action to my form.

My html is -

$(document).ready(function(){

$('#submitId').click(function(){
    var url=$("#urlId").val();
    var xsl=$("#xslId").val();
    alert(xsl);
    $.post('add.htm', {
        url:url,
        xsl:xsl
    },function(data){
        alert("done");
    });
});
});

<form:form commandName="domTool" enctype="multipart/form-data"
method="POST" >

        URL :
        <form:input  path="url"  id="urlId"/>

        Xsl File :
        <form:input type="file" id="xslId" path="file" />

        <input type="button" value="Submit" id="submitId"/>

</form:form>

And my java code is -

@RequestMapping("add")
public String add(@ModelAttribute("tool") DomTool domTool,HttpServletRequest   request,HttpServletResponse response) throws JDOMException, IOException{

    System.out.println("file---------- "+tool.getFile());
    System.out.println("Url---------- "+domTool.getUrl());
    return "success";
}

I'm getting value of url but I'm getting null for domTool.getUrl().

Please anyone help.

Thank you.

Ashwini
  • 41
  • 2
  • 10

1 Answers1

0

You cannot upload a file in this way (by passing its location). Refer to this question for techniques that work.

Community
  • 1
  • 1
mjibson
  • 16,852
  • 8
  • 31
  • 42