如何添加或更改 struts url 标签的参数?
在struts中,我希望有一个基本URL(
<s:url action="getSomeData" id="baseDataUrl">
<s:param name="someID" value="%{currentID}"/>
</s:url>
然后我可以执行
,它会输出类似 /getSomeData.do?someID=5 的内容。 (在这个例子中,我保持参数简单,但你可以想象有更多的默认参数。例如,我正在开发的应用程序有 3 个参数,每个 URL 都相同,还有两个参数会改变。
)希望能够在定义基本 URL 后添加或更改参数。我正在设想两种方法:
<s:url base="baseDataUrl" id="breadUrl">
<s:param name="bread" value="%{'toast'}"/>
</s:url>
然后
将导致 /getSomeData.do?someID=5&bread=toast。另一种方法是使用占位符定义基本 URL:
<s:url action="getSomeData" id="baseDataUrl">
<s:param name="someID" value="%{currentID}"/>
<s:param name="bread" />
<s:param name="jelly" />
</s:url>
然后在我请求属性时填写它们:
<s:param url="baseDataUrl" name="bread" value="%{'toast'}"/>
<s:param url="baseDataUrl" name="jelly" value="%{selectedJam}"/>
因此
将导致 /getSomeData。做?someID=5&面包=吐司&果冻=7。
s:url 的文档 (http://struts.apache.org/2.0 .14/docs/url.html)说“允许动态属性:false”,所以我想我正在冒险进入自定义标签领域。这感觉就像一个常见的用例(使用一些参数定义基本 URL,然后添加或更改其中一些参数),我不想重新发明轮子。搜索没有任何结果,但也许我没有在寻找正确的东西。我愿意接受各种各样的建议!
In struts, I'd like to have a base URL (an <s:url...) set up with a some parameters (<s:param...), and then either add parameters to that URL or change the values of some parameters. For example:
<s:url action="getSomeData" id="baseDataUrl">
<s:param name="someID" value="%{currentID}"/>
</s:url>
I can then do <s:property value="baseDataUrl" />
and it'll spit out something like /getSomeData.do?someID=5. (I'm keeping the params simple for this example, but you can imagine having many more default params. For instance, the app I'm working on has 3 params that are the same for every URL, and two that change.)
I'd like to be able to add or change parameters after defining that base URL. I'm dreaming up two approaches:
<s:url base="baseDataUrl" id="breadUrl">
<s:param name="bread" value="%{'toast'}"/>
</s:url>
And then <s:property value="breadUrl" />
would result in /getSomeData.do?someID=5&bread=toast. Another approach is to define the base URL with placeholders:
<s:url action="getSomeData" id="baseDataUrl">
<s:param name="someID" value="%{currentID}"/>
<s:param name="bread" />
<s:param name="jelly" />
</s:url>
And then fill them in when I ask for the property:
<s:param url="baseDataUrl" name="bread" value="%{'toast'}"/>
<s:param url="baseDataUrl" name="jelly" value="%{selectedJam}"/>
So <s:property value="baseDataUrl" />
would result in /getSomeData.do?someID=5&bread=toast&jelly=7.
The docs for s:url (http://struts.apache.org/2.0.14/docs/url.html) say "Dynamic Attributes Allowed: false" so I think I'm venturing into custom-tag territory. This feels like such a common use case (define a base URL with some params, and then add or change some of them) that I don't want to reinvent the wheel. Searching has yielded nothing, but maybe I'm not looking for the right thing. I'm open to a wide variety of suggestions!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
以下是我能想到的几个选项
在这种方法中,您只是在末尾附加字符串。
Here are few options that I can think of
In this approach you are merely appending strings at the end.