springMVC跨服务器上传 报错:
HTTP Status 500 – Internal Server ErrorType 异常报告
消息 Request processing failed; nested exception is com.sun.jersey.api.client.UniformInterfaceException: PUT http://localhost:9090/uploads/2fdf8b2244324d1d945934918226a3be_11.jpg returned a response status of 405 Method Not Allowed
描述 服务器遇到一个意外的情况,阻止它完成请求。
Exception
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is com.sun.jersey.api.client.UniformInterfaceException: PUT http://localhost:9090/uploads/2fdf8b2244324d1d945934918226a3be_11.jpg returned a response status of 405 Method Not Allowedorg.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:986)org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:881)javax.servlet.http.HttpServlet.service(HttpServlet.java:660)org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:855)javax.servlet.http.HttpServlet.service(HttpServlet.java:741)org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:200)org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
Root Cause
com.sun.jersey.api.client.UniformInterfaceException: PUT http://localhost:9090/uploads/2fdf8b2244324d1d945934918226a3be_11.jpg returned a response status of 405 Method Not Allowedcom.sun.jersey.api.client.WebResource.voidHandle(WebResource.java:709)com.sun.jersey.api.client.WebResource.put(WebResource.java:208)com.itheima.UserController.FileUpload3(UserController.java:109)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:209)org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:136)org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:102)org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:871)org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:777)org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:991)org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:925)org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:978)org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:881)javax.servlet.http.HttpServlet.service(HttpServlet.java:660)org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:855)javax.servlet.http.HttpServlet.service(HttpServlet.java:741)org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:200)org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
):注意 主要问题的全部 stack 信息可以在 server logs 里查看Apache Tomcat/9.0.30
POP引入包
<dependency><groupId>commons-fileupload</groupId><artifactId>commons-fileupload</artifactId><version>1.3.1</version></dependency><dependency><groupId>commons-io</groupId><artifactId>commons-io</artifactId><version>2.4</version></dependency><dependency><groupId>com.sun.jersey</groupId><artifactId>jersey-core</artifactId><version>1.18.1</version></dependency><dependency><groupId>com.sun.jersey</groupId><artifactId>jersey-client</artifactId><version>1.18.1</version></dependency>
解决:(修改tomcat默认配置,tomcat默认只读)
tomcat目录中conf/web.xml加入readonly=false这一部分
<servlet><servlet-name>default</servlet-name><servlet-class>org.apache.catalina.servlets.DefaultServlet</servlet-class><init-param><param-name>debug</param-name><param-value>0</param-value></init-param><init-param><param-name>listings</param-name><param-value>false</param-value></init-param><init-param><param-name>readonly</param-name><param-value>false</param-value></init-param><load-on-startup>1</load-on-startup></servlet>