File upload SpringWebFlow-使用多部分/表单数据和文件上载时出现IllegalStateException

File upload SpringWebFlow-使用多部分/表单数据和文件上载时出现IllegalStateException,file-upload,multipartform-data,spring-webflow-2,File Upload,Multipartform Data,Spring Webflow 2,我正在尝试将文件上载添加到SpringWebFLOG表单处理中。只要表单enctype没有设置为多部分/表单数据,表单提交就可以正常工作。但在我将enctype=“multipart/form data”添加到我的Spring表单后,出现了以下异常: java.lang.IllegalStateException: A flow execution action URL can only be obtained in a RenderRequest or a ResourceRequest

我正在尝试将文件上载添加到SpringWebFLOG表单处理中。只要表单enctype没有设置为多部分/表单数据,表单提交就可以正常工作。但在我将enctype=“multipart/form data”添加到我的Spring表单后,出现了以下异常:

java.lang.IllegalStateException: A flow execution action URL can only be obtained in a RenderRequest or a ResourceRequest
    at org.springframework.webflow.context.portlet.PortletExternalContext.getFlowExecutionUrl(PortletExternalContext.java:215)
    at org.springframework.webflow.engine.impl.RequestControlContextImpl.getFlowExecutionUrl(RequestControlContextImpl.java:178)
    at org.springframework.webflow.mvc.view.AbstractMvcView.render(AbstractMvcView.java:189)
    at org.springframework.webflow.engine.ViewState.render(ViewState.java:293)
    at org.springframework.webflow.engine.ViewState.refresh(ViewState.java:242)
    at org.springframework.webflow.engine.ViewState.resume(ViewState.java:220)
    at org.springframework.webflow.engine.Flow.resume(Flow.java:537)
    at org.springframework.webflow.engine.impl.FlowExecutionImpl.resume(FlowExecutionImpl.java:259)
    at org.springframework.webflow.executor.FlowExecutorImpl.resumeExecution(FlowExecutorImpl.java:169)
    at org.springframework.webflow.mvc.portlet.FlowHandlerAdapter.handleAction(FlowHandlerAdapter.java:161)
    at org.springframework.web.portlet.DispatcherPortlet.doActionService(DispatcherPortlet.java:670)
    at org.springframework.web.portlet.FrameworkPortlet.processRequest(FrameworkPortlet.java:520)
    at org.springframework.web.portlet.FrameworkPortlet.processAction(FrameworkPortlet.java:461)
    at com.liferay.portlet.FilterChainImpl.doFilter(FilterChainImpl.java:71)
我已将CommonMultipartResolver添加到我的spring上下文中:

<bean id="multipartResolver"
      class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
  <!-- Limit uploads to one byte smaller than the server is allowed to handle -->
  <property name="maxUploadSize" value="100000" />
</bean>
有什么想法吗?有什么问题吗?正如我所说,如果没有enctype=“multipart/form data”,表单处理工作会很好


谢谢

您正在使用org.springframework.web.multipart.commons.commons multipartresolver,它不知道portlet上下文。 您需要将CommonsMultipartResolver更改为:

    <bean id="portletMultipartResolver"
        class="org.springframework.web.portlet.multipart.CommonsPortletMultipartResolver">
        <!-- one of the properties available; the maximum file size in bytes -->
        <property name="maxUploadSize" value="100000"/>
    </bean>

您是否通过调试检查它是否进入portletAction.processForm方法?发布错误的完整跟踪。嗨@Prasad,谢谢你的回复。在我的表单中使用多部分/表单数据时,永远不会输入portletAction.processForm方法。我用调试器检查了一下。可以看到完整的堆栈跟踪。在我看来,似乎将跳过操作阶段(调试器直接进入视图状态“state1”并尝试呈现视图),但我在流配置文件中找不到任何错误,正如我之前所说的,没有多部分/表单数据enctype,表单处理工作正常(提交后输入processForm方法).谢谢你@Prasad,这解决了我的问题。正如我所料,这是我愚蠢的错误:/。。。
<portlet:actionURL var="processFormAction" >
    <portlet:param name="execution" value="${flowExecutionKey}"/>
</portlet:actionURL>
<form:form action="${processFormAction}" modelAttribute="customerModel" enctype="multipart/form-data" method="post" >
    <form:input path="firstName" cssClass="input-size-1 valid-required" />
    <form:input path="lastName" cssClass="input-size-1  valid-required" />
    <input name="avatar" id="avatar" type="file"/>
    <input type="submit" name="_eventId_submit" id="send" value="Submit"/>
</form:form>
<view-state id="state1" model="customerModel">
    ...
    <transition on="submit" to="submitFormActions"/>
</view-state>

<action-state id="submitFormActions">
    <evaluate expression="portletAction.processForm(customerModel, flowRequestContext)" />
    <transition on="success" to="state2"/>
    <transition on="error" to="state1" />
</action-state>
public class CustomerModel implements Serializable{
    private String firstName;
    private String lastName;
    private MutlipartFile avatar;

    ...
    //public getters and setters
}
    <bean id="portletMultipartResolver"
        class="org.springframework.web.portlet.multipart.CommonsPortletMultipartResolver">
        <!-- one of the properties available; the maximum file size in bytes -->
        <property name="maxUploadSize" value="100000"/>
    </bean>
    Any configured PortletMultipartResolver bean must have the following id (or name): "portletMultipartResolver". 
    If you have defined your PortletMultipartResolver with any other name, then the DispatcherPortlet will not 
    find your PortletMultipartResolver, and consequently no multipart support will be in effect.