# SpringMVC跨伺服器上傳檔案出現的問題
阿新 • • 發佈:2020-08-23
SpringMVC跨伺服器上傳檔案出現的問題
一、上傳檔案檔名有中文,會報400錯!
Type 異常報告 訊息 Request processing failed; nested exception is com.sun.jersey.api.client.UniformInterfaceException: PUT http://localhost:9090/Springmvc_uploadServer/uploads/cc24a16106b34d179555cceea1cc2b24QQ圖片20200720135759.jpg returned a response status of 400 Bad Request 描述 伺服器遇到一個意外的情況,阻止它完成請求。 Exception org.springframework.web.util.NestedServletException: Request processing failed; nested exception is com.sun.jersey.api.client.UniformInterfaceException: PUT http://localhost:9090/Springmvc_uploadServer/uploads/cc24a16106b34d179555cceea1cc2b24QQ圖片20200720135759.jpg returned a response status of 400 Bad Request org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1014) org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:909) javax.servlet.http.HttpServlet.service(HttpServlet.java:660) org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883) javax.servlet.http.HttpServlet.service(HttpServlet.java:741) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201) org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) Root Cause com.sun.jersey.api.client.UniformInterfaceException: PUT http://localhost:9090/Springmvc_uploadServer/uploads/cc24a16106b34d179555cceea1cc2b24QQ圖片20200720135759.jpg returned a response status of 400 Bad Request com.sun.jersey.api.client.WebResource.voidHandle(WebResource.java:709) com.sun.jersey.api.client.WebResource.put(WebResource.java:208) com.example.controller.TestController2.testFileUpload3(TestController2.java:119) sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) java.lang.reflect.Method.invoke(Method.java:498) org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:190) org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:138) org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:105) org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:879) org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:793) org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87) org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1040) org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:943) org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006) org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:909) javax.servlet.http.HttpServlet.service(HttpServlet.java:660) org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883) javax.servlet.http.HttpServlet.service(HttpServlet.java:741) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201) org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
解決方法:刪除上傳檔名稱的中文部分!
二、405錯誤
解決方法:改一下tomcat許可權:修改readonly為false!
相關配置(在tomcat/conf/web.xml中加):
<init-param>
<param-name>readonly</param-name>
<param-value>false</param-value>
</init-param>
三、409錯誤(接收檔案的那一端沒有生成指定的資料夾,如:upload資料夾)
解決方法:手動在接收端的WebApp下新建upload資料夾!