java 如何访问Struts2中的请求参数?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1183009/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to access request parameters in Struts2?
提问by Zaheer Baloch
I am trying to access request parameters on a web page and trying to set a hidden fields value to the passed parameter. How can I achieve this using struts2 tags?
我正在尝试访问网页上的请求参数并尝试将隐藏字段值设置为传递的参数。如何使用 struts2 标签实现这一点?
Something like...
就像是...
<s:hidden name="myfield" value="#parameters['myparam']"/>
I have tries using the parameters object but it does not work!
我曾尝试使用参数对象,但它不起作用!
Thanks in advance.
提前致谢。
回答by Brian Yarger
Adding Zahieer's answer out of his comment so the question can be "answered":
在他的评论中添加 Zahier 的回答,以便可以“回答”这个问题:
<s:hidden name="myfield" value="%{#parameters['mparam']}"></s:hidden>
回答by andynu
If you add a String getMyParam(),setMyParam(String val) to the action rendering the form then you can use
如果将 String getMyParam(),setMyParam(String val) 添加到呈现表单的动作中,则可以使用
<s:hidden name="myfield" value="${myParam}" />

