使用Spring WebFlow 2.4.0上传文件,未绑定参数

使用Spring WebFlow 2.4.0上传文件,未绑定参数,第1张

使用Spring WebFlow 2.4.0上传文件,未绑定参数

由于在Web应用程序中使用Spring Security 4.xx,我们遇到了同样的问题。问题是a

org.springframework.security.web.context.HttpSessionSecurityContextRepository$Servlet3SaveToSessionRequestWrapper
不是的实例
org.springframework.web.multipart.MultipartHttpServletRequest
但包含一个实例。强制转换将不起作用,并且
ClassCastException
会发生。

那就是为什么

if (request instanceof MultipartHttpServletRequest) {    // ... process multipart data}

永远不可能

true

这个想法是

org.springframework.web.multipart.support.StandardMultipartHttpServletRequest
从本地人创建一个
HttpServletRequest
并且有效。

在我们的WebApp中,我们使用Spring Webflow文档第6.5.1节中指示的Pojo *** 作。调用POJO动作。

解决方法:

PojoAction.java

public String fileUpload(RequestContext requestContext) {    final ServletExternalContext context = (ServletExternalContext) requestContext.getExternalContext();    final MultipartHttpServletRequest multipartRequest = new StandardMultipartHttpServletRequest((HttpServletRequest)context.getNativeRequest());    final File file = multipartRequest.getFile("file");    fileUploadHandler.processFile(file); //do something with the submitted file}

在flow.xml中,我们具有以下 *** 作状态:

<action-state id="upload-action">    <evaluate expression="pojoAction.uploadFile(flowRequestContext)"/>    <transition to="show"/></action-state>

在这种情况下,不需要绑定到模型。希望对您有所帮助!

根据更新1

在web.xml中,必须在SpringSecurityFilterChain之前声明CSRF保护过滤器。

在我们的应用程序中,web.xml看起来像这样

    <filter>        <filter-name>csrfFilter</filter-name>        <filter-class> org.springframework.web.filter.DelegatingFilterProxy        </filter-class>        <async-supported>true</async-supported>    </filter>    <filter-mapping>        <filter-name>csrfFilter</filter-name>        <url-pattern>/*</url-pattern>     </filter-mapping>     <filter>        <filter-name>springSecurityFilterChain</filter-name>        <filter-class>org.springframework.web.filter.DelegatingFilterProxy        </filter-class>      </filter>      <filter-mapping>         <filter-name>springSecurityFilterChain</filter-name>         <url-pattern>/*</url-pattern>         <dispatcher>REQUEST</dispatcher>         <dispatcher>ERROR</dispatcher>      </filter-mapping>


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5500178.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-12
下一篇 2022-12-12

发表评论

登录后才能评论

评论列表(0条)

保存