使用Spring Web Flow上传文件

时间:2019-01-02 05:30:18

标签: spring-mvc spring-webflow-2

我使用select pe.idprd, p.nmprd, sum(pe.sisastock) as 'totalsisastock', pe.tglmasuk, k.idkat, d.iddvs from tbproduk as p left join tbpembelian as pe on pe.idprd = p.idprd join tbkategori as k on p.idkat = k.idkat join tbdivisi as d on p.iddvs = d.iddvs having sum(pe.sisastock) > 0 order by pe.tglmasuk DESC 搜索并阅读了findOne({ "GiveawayHostID": name }). sort({ _id: -1}). exec(function (err, host) { 上的多个答案,但似乎所有答案都相同。因此发布。

file upload

流量

Spring Web Flow

JSP

public class FileUploadForm { private transient MultipartFile file; //Additional fields }

XML

<view-state id="start" model="fileUploadForm">
    <transition on="submit" to="submit"/>
    <transition on="cancel" to="cancel"/>
</view-state>

<action-state id="submit">
    <evaluate expression="someActions.review(fileUploadForm)" />
    <transition on="success" to="home"/>
</action-state>

JAVA


   <form:form modelAttribute="fileUploadForm" enctype="multipart/form-data">
        <input type="hidden" name="_flowExecutionKey" value="${flowExecutionKey}"/>
        <form:label path="file">Upload File</form:label>
        <form:input type="file" path="file"/>
        <button name="_eventId_upload">Upload Button</button>
    </form:form>

<!--<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">--> <!--<property name="maxUploadSize" value="100000"/>--> <!--</bean>--> <bean id="filterMultipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"> <property name="maxUploadSize" value="100000" /> </bean> public String review(FileUploadForm fileUploadForm) { LOG.info("{}", fileUploadForm.getFile().getContentType()); return "success"; } 为空。我确实在表格中填写了其他字段,但没有填写文件字段。

有人能指出我正确的方向吗?使用LOG.info

1 个答案:

答案 0 :(得分:0)

尝试使用常规输入文件:

<input type="file" name="file" id="file"/>

[EDIT]为完整起见,我的工作代码也使用以下表单标记:

<form:form modelAttribute="fileUploadForm" action="${flowExecutionUrl}&${_csrf.parameterName}=${_csrf.token}" enctype="multipart/form-data">

和这种类型的提交按钮:

<input type="submit" id="upload" name="_eventId_upload" value="Upload"></span>