我在使用 jquery 向 Spring Controller 执行 ajax POST 时遇到问题。 该帖子包含多个参数,其中有一个 64 进制字符串,表示从客户端发送的文件。 现在,如果文件小于 1.5~2mb,请求就可以正常完成。 如果超过此大小, Controller 将返回该请求在语法上不正确。 我在客户端使用encodeuricomponent。
在这两种情况下,如果我从 HTTPServletRequest 获取阅读器,我就可以获得整个 POST 表单。不用说,它非常慢。 如果文件大于 2 MB,我还可以通过上面引用的方法获取整个查询,但不能通过 getParameter() 方法(HTTPServletRequest)或注释(@requestParam("file"))获取。
这是我的 Controller :
@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){
最佳答案
要使用 Spring 上传文件,请尝试使用多部分支持。引用链接Spring's multipart (fileupload) support
关于java - AJAX POST 到 Spring Controller 中的空参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20354172/