com.sun.jersey.api.client.UniformInterfaceException ... returned a response status of 403 Forbidden

Posted Chris-Chang

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了com.sun.jersey.api.client.UniformInterfaceException ... returned a response status of 403 Forbidden相关的知识,希望对你有一定的参考价值。

我在学习SpringMVC跨服务器文件上传时遇到了以下错误Request processing failed; nested exception is com.sun.jersey.api.client.UniformInterfaceException: PUT http://localhost:9090/fileuploadserver/uploads/faa16d8fe48e49ae8ec8fd07be023c0f_test1.png returned a response status of 403 Forbidden
具体错误如下

07-May-2020 21:07:20.957 严重 [http-apr-8080-exec-1] org.apache.catalina.core.StandardWrapperValve.invoke Servlet.service() for servlet [dispatcherServlet] in context with path [/day02_02fileupload] threw exception [Request processing failed; nested exception is com.sun.jersey.api.client.UniformInterfaceException: PUT http://localhost:9090/fileuploadserver/uploads/faa16d8fe48e49ae8ec8fd07be023c0f_test1.png returned a response status of 403 Forbidden] with root cause
 com.sun.jersey.api.client.UniformInterfaceException: PUT http://localhost:9090/fileuploadserver/uploads/faa16d8fe48e49ae8ec8fd07be023c0f_test1.png returned a response status of 403 Forbidden
	at com.sun.jersey.api.client.WebResource.voidHandle(WebResource.java:709)
	at com.sun.jersey.api.client.WebResource.put(WebResource.java:208)
	at com.chang.controller.UserController.fileupload3(UserController.java:58)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:567)
	at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:190)
	at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:138)
	at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:105)
	at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:879)
	at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:793)
	at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)
	at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1040)
	at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:943)
	at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006)
	at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:909)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:648)
	at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:292)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
	at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
	at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201)
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:94)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
	at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:620)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:502)
	at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1132)
	at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:684)
	at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2527)
	at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2516)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
	at java.base/java.lang.Thread.run(Thread.java:830)

原因

tomcat服务器目前对项目文件没有写入权限,在tomcat配置文件中(D:\\Program Files\\Tomcat\\apache-tomcat-8.0.50\\conf\\web.xml)113行左右,添加如下代码

		<init-param> 
			<param-name>readonly</param-name> 
			<param-value>false</param-value> 
		</init-param>

添加后部分配置如下:


重启服务器即可。

以上是关于com.sun.jersey.api.client.UniformInterfaceException ... returned a response status of 403 Forbidden的主要内容,如果未能解决你的问题,请参考以下文章

com.sun.jersey.api.client.UniformInterfaceException ... returned a response status of 403 Forbidden

nested exception is com.sun.jersey.api.client.UniformInterfaceException: PUT

Jersey实现Client端:GET/PUT/POST/DELETE

使用 Jersey 客户端的 PATCH 请求

idea 内置tomcat jersey 跨服务器 上传文件报400错误

note001