Java 将文件上载到Spring时,net::ERR_连接中止的可能原因是什么
pI am使用plupload(plupload.com)jQuery插件将图像文件AJAX到JavaSpring服务器。我尝试了服务器端RESTful控制器端点的不同实现。我附上了处理文件上传url的具体方法。任何帮助都将不胜感激。多谢各位Java 将文件上载到Spring时,net::ERR_连接中止的可能原因是什么,java,jquery,spring,Java,Jquery,Spring,pI am使用plupload(plupload.com)jQuery插件将图像文件AJAX到JavaSpring服务器。我尝试了服务器端RESTful控制器端点的不同实现。我附上了处理文件上传url的具体方法。任何帮助都将不胜感激。多谢各位 @RequestMapping(value = "/pictureUpload", method = RequestMethod.POST ) public @ResponseBody String productPictureUploadPost(@R
@RequestMapping(value = "/pictureUpload", method = RequestMethod.POST )
public @ResponseBody
String productPictureUploadPost(@RequestBody MultipartFile multipartFile) {
HomeController.logger.info("In method productPictureUploadPost in SettingsPanelController. : Entering");
String orgName = multipartFile.getOriginalFilename();
String filePath = "/my_uploads/" + orgName;
File dest = new File(filePath);
try {
multipartFile.transferTo(dest);
} catch (IllegalStateException e) {
e.printStackTrace();
return "File uploaded failed:" + orgName;
} catch (IOException e) {
e.printStackTrace();
return "File uploaded failed:" + orgName;
}
HomeController.logger.info("In method productPictureUploadPost in SettingsPanelController. Exiting : " + "File uploaded:" + orgName);
return "File uploaded:" + orgName;
}
我还附加了servlet.xml多部分解析器声明
<bean class="org.springframework.web.multipart.support.StandardServletMultipartResolver"/>
在文件上载的上下文中,当HTTP服务器未完全读取客户端的HTTP请求正文并在上载过程中中止连接时,会发生
net::ERR_CONNECTION_ABORTED
。这通常发生在上载的文件太大时,服务器继续读取请求并提前失败是没有意义的
中止连接意味着客户端在收到响应之前上传文件不会浪费带宽,但会触发上述错误
HTTP提供了提前终止连接的功能,Expect:100 continue
请求头和100 continue
响应状态,您可以在此处阅读:
不幸的是,大多数浏览器不会在文件上载()期间发送它
但是,由于您在客户端使用Flash/Silverlight进行上传,我建议您考虑让您的上传小部件向服务器发送
Expect:100 continue
。您从哪里得到错误?在浏览器中,通过firebug。看起来不像是Spring错误。可能是浏览器设置或防火墙问题,我只是在寻找一些类似问题的经验,以便在排除故障时缩小范围。
$(document).ready(function() {
$("#uploader").plupload({
// General settings
runtimes: 'html5,flash,silverlight,html4',
url: "/pictureUpload",
// Maximum file size
max_file_size: '1000mb',
// User can upload no more then 20 files in one go (sets multiple_queues to false)
max_file_count: 3,
// Specify what files to browse for
filters: [
{ title: "Image files", extensions: "jpg,jpeg,gif,png" }
],
// Rename files by clicking on their titles
rename: true,
// Sort files
sortable: true,
// Enable ability to drag'n'drop files onto the widget (currently only HTML5 supports that)
dragdrop: true,
// Views to activate
views: {
list: true,
thumbs: true, // Show thumbs
active: 'thumbs'
},
// Flash settings
flash_swf_url : 'http://rawgithub.com/moxiecode/moxie/master/bin/flash/Moxie.cdn.swf',
// Silverlight settings
silverlight_xap_url : 'http://rawgithub.com/moxiecode/moxie/master/bin/silverlight/Moxie.cdn.xap'
});
});