You*_*sef 17 java spring tomcat spring-mvc
有时当我尝试在远程vps上传文件时,我得到此异常(上传进程停止在60%)
06-Jan-2016 11:59:36.801 SEVERE [http-nio-54000-exec-9] org.apache.catalina.core.StandardWrapperValve.invoke Servlet.service() for servlet [mvc-dispatcher] in context with path [] threw exception [Request processing failed;
nested exception is org.springframework.web.multipart.MultipartException: Could not parse multipart servlet request;
nested exception is org.apache.commons.fileupload.FileUploadBase$IOFileUploadException: Processing of multipart/form-data request failed. Unexpected EOF read on the socket]
with root cause
java.io.EOFException: Unexpected EOF read on the socket
Run Code Online (Sandbox Code Playgroud)
并且在Google Chrome连接中丢失了,就像服务器停机一样,我明白了ERR_CONNECTION_ABORTED
我在spring mvc上传这样的文件
public void save_file(MultipartFile upfile , String path){
try {
File fichier = new File( path ) ;
byte[] bytes = upfile.getBytes();
BufferedOutputStream stream = new BufferedOutputStream(new FileOutputStream( fichier ));
stream.write(bytes);
stream.close();
System.out.println( "You successfully uploaded " + upfile.getOriginalFilename() + "!" );
} catch (Exception e) {
System.out.println( "You failed to upload " + upfile.getOriginalFilename() + " => " + e.getMessage() ); ;
}
}
Run Code Online (Sandbox Code Playgroud)
我的控制器:
@RequestMapping(value = "/administration/upload", method = RequestMethod.POST)
public String Upload_AO_journal(
@ModelAttribute UploadForm uploadForm,
Model map , HttpServletRequest request, HttpSession session ) throws ParseException, UnsupportedEncodingException {
Run Code Online (Sandbox Code Playgroud)
我的豆子
public class UploadForm {
...
public MultipartFile scan;
Run Code Online (Sandbox Code Playgroud)
那怎么能解决这个问题呢?
你试过流吗?
Jsp代码:
<form method="POST" onsubmit="" ACTION="url?${_csrf.parameterName}=${_csrf.token}" ENCTYPE="multipart/form-data">
控制器:
@RequestMapping(
value = "url", method = RequestMethod.POST
)
public void uploadFile(
@RequestParam("file") MultipartFile file
) throws IOException {
InputStream input = upfile.getInputStream();
Path path = Paths.get(path);//check path
OutputStream output = Files.newOutputStream(path);
IOUtils.copy(in, out); //org.apache.commons.io.IOUtils or you can create IOUtils.copy
}
Run Code Online (Sandbox Code Playgroud)
所有这些都适用于我的弹簧4.0和弹簧安全.
其次,您应该检查http连接是否超时.Chrome不支持该配置.所以你可以使用firefox并点击这里http://morgb.blogspot.com.es/2014/05/firefox-29-and-http-response-timeout.html.
| 归档时间: |
|
| 查看次数: |
25259 次 |
| 最近记录: |