AJAX中的空参数POST到Spring Controller

时间:2013-12-03 14:43:06

标签: java jquery ajax spring-mvc post

我在使用jquery对Spring Controller进行ajax POST时遇到了麻烦。 该帖子包含几个参数,其中有一个base 64字符串,表示从客户端发送的文件。 现在,如果文件低于1.5~2mb,请求就完成了。 如果超过此大小,控制器将返回请求在语法上不正确的情况。 我在客户端使用encodeuricomponent。

在这两种情况下,如果我从HTTPServletRequest获取读者,我可以获得整个POST表单。不用说,它超级慢。 如果文件大于2 mb,我也可以通过上面引用的方法获取整个查询,但不能通过getParameter()方法(HTTPServletRequest)或注释(@requestParam(“file”))来获取。

这是我的控制者:

@ResponseBody
    @RequestMapping(value="/uploadClient", method = RequestMethod.POST)
    public String uploadClient( Model model, HttpServletRequest req,@RequestParam(value="file", required = false) String file, @RequestParam(value="projectID") Integer projectID, 
            @RequestParam(value="opID") Integer opID, @RequestParam(value="releaseID") Integer releaseID,
            @RequestParam(value="name") String name, @RequestParam(value="url") String url, 
            @RequestParam(value="date") String date,
            @RequestParam(value="version") String version, @RequestParam(value="comment") String comment,
            @RequestParam(value="fileName") String fileName){

1 个答案:

答案 0 :(得分:0)

要使用Spring上传文件,请尝试使用multipart支持。请参阅链接Spring's multipart (fileupload) support

相关问题