创建MultipartHttpServletRequest然后获取Exception

时间:2016-02-05 09:42:44

标签: java spring

创建MultipartHttpServletRequest然后获取Exception。 我已经创建了HttpServletRequest,但在使用MultipartHttpServletRequest进行转换时,则获得了Exception 我的代码是

public void uploadFileOnLocal(@RequestParam Long caseId, HttpServletRequest request ,HttpServletResponse response) {

MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;

例外是:

   SEVERE: Servlet.service() for servlet [download] in context with path   [/localdownload] threw exception [Request processing failed; nested exception is           java.lang.ClassCastException: org.apache.catalina.connector.RequestFacade cannot be cast to org.springframework.web.multipart.MultipartHttpServletRequest] with root cause
java.lang.ClassCastException: org.apache.catalina.connector.RequestFacade cannot be cast to org.springframework.web.multipart.MultipartHttpServletRequest
at com.triventkiosk.controller.DownloadController.uploadFileOnLocal(DownloadController.java:98)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:221)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:137)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:110)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:776)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:705)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:959)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:966)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:868)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:644)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:842)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:610)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:537)

2 个答案:

答案 0 :(得分:2)

您在JSP中的标记可能没有enctype =“multipart / form-data”作为属性,将表单标记为,并且此错误将被删除。例如:

<form method="post" enctype="multipart/form-data">
</form>

根据您的Spring版本,您可能需要正确地进行转换 - 请检查此帖子How to get a MultipartHttpServletRequest from RequestContextHolder?

答案 1 :(得分:2)

你需要

node('git && linux') {
    // dome some stuff here
}

stage "Running unit tests for $REVISION"
build job: 'unit-tests', parameters: [[$class: 'StringParameterValue', name: 'REVISION', value: REVISION], [$class: 'StringParameterValue', name: 'REFSPEC', value: REFSPEC]]

stage "Running integration tests $REVISION"
def jobs = [:]
jobs['integration-tests-1']={build job: 'integration-tests-job-1', parameters: [[$class: 'StringParameterValue', name: 'REVISION', value: REVISION], [$class: 'StringParameterValue', name: 'REFSPEC', value: REFSPEC]]}
jobs['integration-tests-2']={build job: 'integration-tests-job-2', parameters: [[$class: 'StringParameterValue', name: 'REVISION', value: REVISION], [$class: 'StringParameterValue', name: 'REFSPEC', value: REFSPEC]]}
jobs['integration-tests-3']={build job: 'integration-tests-job-3', parameters: [[$class: 'StringParameterValue', name: 'REVISION', value: REVISION], [$class: 'StringParameterValue', name: 'REFSPEC', value: REFSPEC]]}

parallel jobs

// Here I would like to add something like
// aggregateDownstream('unit-tests', 'integration-tests-1', 'integration-tests-2', 'integration-tests-3'