【问题标题】:Upload file and send parameters to spring portlet controller上传文件并将参数发送到spring portlet控制器
【发布时间】:2014-12-13 20:49:13
【问题描述】:

谁能告诉我如何使用spring mvc portlet 控制器上传文件并将输入参数传递给控制器​​?

jsp中的动作URL和表单:

<portlet:actionURL var="addDetailsURL"> 
    <portlet:param name="addDetails" value="addDetailsValue"/> 
</portlet:actionURL>


<div id = "<portlet:namespace/>addDetailsDIV" >
    <form action="${addDetailsURL}" enctype="multipart/form-data" method="post">

        <input style="display:block;" type="text" name="selectedDetail" id='selectedDetail'/> <%-- holds the parameter that is supposed to be passed to the controller --%>
        <table width = 100% cellspacing="5" cellpadding="5">
            <tr>
                <td colspan='2'><fmt:message key = "selectFileUploadTxt"/></td>
            </tr>
            <tr>
                <td colspan='2'><input id="uploadedFile" type="file" name="uploadedFile" /></td>
            </tr>
            <tr>
                <td >
                <span id="<portlet:namespace />closeAddDetailDia">cancel</span>
                </td>
                <td align="left">
                <Button id="uploadButton"><fmt:message key="addDetailButtonTxt" /></Button>

                </td>
            </tr>
        </table>
    </form>
</div>

在提交时,请求转到控制器,但“selectedDetail”参数为空。

控制器代码:

@RequestMapping("VIEW")
public class AddDetailsController {

    /**
     * 
     * @param actionRequest
     * @param actionResponse
     * @return
     * @throws IOException 
     */
    @SuppressWarnings({ "rawtypes", "unused" })
    @ActionMapping(params = "addDetails=addDetailsValue")
    public String fileUpload(ActionRequest actionRequest, ActionResponse actionResponse,
        @RequestParam String selectedDetail
            ) throws PortletException, IOException {
        System.out.println("selectedDetail : " + selectedDetail); // it is null
        System.out.println("selectedDetail : " + actionRequest.getParameter("selectedDetail")); // it is null

文件上传部分工作正常,但我没有得到“selectedDetail”参数。请帮忙。

环境细节

  1. WebSphere Portal v7002
  2. IDE - RAD v8.5
  3. 春季版 3.1.0

如果您需要任何其他详细信息,请告诉我。

【问题讨论】:

    标签: spring spring-mvc websphere-portal spring-portlet-mvc


    【解决方案1】:

    在后端,定义一个 bean 来保存包括文件在内的表单数据。

    我称之为FormBean。 FormBean 应该有一个类型为
    私有 org.springframework.web.multipart.commons.CommonsMultipartFile 文件的实例变量;

    表单中的更改将包括在表单元素中包含“commandName”和“路径”:

    commandName="formBean"... />

    &

    以下链接很好地解释了这一点: https://portalhub.wordpress.com/2012/05/20/spring-mvc-portlet-file-upload-and-download/

    【讨论】:

      猜你喜欢
      • 2012-08-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-11
      • 2018-02-15
      • 1970-01-01
      • 2016-02-07
      • 1970-01-01
      • 2018-01-18
      相关资源
      最近更新 更多