struts2 s:form 元素修剪 action 属性中的 s:url 参数 [英] struts2 s:form element trims the s:url parameter in the action attribute

查看:18
本文介绍了struts2 s:form 元素修剪 action 属性中的 s:url 参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 <s:url> 创建一个类似 removeAction.action?id=10 的 URL,应该由 中的 action 属性使用><s:form> 元素.

这里的问题是当 <s:form> 转换为 <form> 元素时,我只能将动作属性值视为 action=/project/removeAction.action".id 参数正在被修剪.我想要的结果是 action="/project/removeAction.action?id=10"

<s:url var="actionUrl" action="removeAction" includeContext="false"><s:param name="id" value="%{id}"/></s:url><s:form action="%{actionUrl}" method="post" enctype="multipart/form-data" >

<s:file name="imgUpload"/><s:提交>上传</提交></div></s:form>

最近我将 struts2 核心版本升级到 2.3.12,我遇到了这个问题.此问题在版本 2.3.4.1 之后开始

而且我不想使用 hidden 属性来传递参数,因为当文件很大要上传时,此参数会丢失.

有什么解决办法吗?

解决方案

也许你可以使用通配符映射

<action name="removeAction\*" class=".."></动作>

并将 id 作为它自己的 url 的一部分传递.例如:removeAction/101

参考 http://struts.apache.org/release/2.3.x/docs/wildcard-mappings.html

I am using <s:url> to create a URL like removeAction.action?id=10 which should be used by the action attribute in the <s:form> element.

The issue here is when the <s:form> converts to <form> element I can only see the action attribute value as action="/project/removeAction.action". The id parameter is getting trimmed. The result I wanted is action="/project/removeAction.action?id=10"

<s:url var="actionUrl" action="removeAction" includeContext="false">
  <s:param name="id" value="%{id}" /> 
</s:url>

<s:form action="%{actionUrl}" method="post" enctype="multipart/form-data" >
 <div>
  <s:file name="imgUpload"/>
  <s:submit> upload </submit>
 </div>
</s:form>

Recently I upgrade the struts2 core version to 2.3.12 and I am getting this issue. This issue starts after version 2.3.4.1

And I don't want to use a hidden attribute to pass the parameter as this parameter get lost when the file size is big to upload.

Is there any solution for this?

解决方案

May be you could use a wildcard mapping

<action name="removeAction\*" class="..">

</action>

And pass the id as part of the url it self.e.g: removeAction/101

Refer http://struts.apache.org/release/2.3.x/docs/wildcard-mappings.html

这篇关于struts2 s:form 元素修剪 action 属性中的 s:url 参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆