首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >表单上的文件上传:使用Spring Roo更新

表单上的文件上传:使用Spring Roo更新
EN

Stack Overflow用户
提问于 2012-08-29 02:17:40
回答 1查看 844关注 0票数 2

我正在为表单上的文件上传而苦苦挣扎:用spring roo更新。

对于创建部分,我使用了Jose Delgado here提供的表单:多标签。定制的form:multi标签将enctype="multipart/ form -data“添加到表单中,这样做效果很好。

问题是当您想要为您的更新表单提供文件上传功能时。默认情况下,Spring Roo (可能是spring mvc,我不知道)会将应用程序“enctype=/x-www- form -urlencoded”设置为更新表单(form:update tag)。如果我在上传表单中将enctype属性设置为enctype="multipart/ form -data“,那么在提交表单时,服务器将执行控制器的"create”方法,而不是"udpate“方法……

你知道我们怎么才能(简单地)解决这个问题吗?我已经花了相当多的时间在它上面,我发现自己失去了灵感(也许是因为这是一天的末日,也是:)。

谢谢你的帮忙,

亲切的问候

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-08-29 20:25:10

OK...It看起来RequestMapping有点小问题。

无论出于什么原因,当form:update标记中的multipart属性被设置为"true“时,方法参数就被设置为"POST”。

作为一种变通方法,我在create方法的开头检查了_method参数。如果设置为"PUT",我将返回update方法的值。

代码语言:javascript
运行
复制
    @RequestMapping(method = RequestMethod.POST, produces = "text/html")
    public String create(@Valid ActionRequest actionRequest, BindingResult bindingResult, Model uiModel, HttpServletRequest httpServletRequest) {

        // Work around dispatcher bug: if the multipart attribute of the form is set to true,
        // submission of the update form routes to create method
        String toto = httpServletRequest.getParameter("_method");

        if(httpServletRequest.getParameter("_method").equals("PUT")){
            return this.update(actionRequest,bindingResult,uiModel,httpServletRequest);
        }
   ...
}
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12165164

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档