我怎样才能在JSP中获取参数? [英] How could I get a parameter in JSP?
本文介绍了我怎样才能在JSP中获取参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的行动 execute()
方法,
@Override
public String execute() throws Exception {
ActionContext aContext = ActionContext.getContext();
aContext.getParameters().put("reqVar1", "reqVar1-Value");
return SUCCESS;
}
我想在JSP中获取参数值,如下面的代码,
I want to get the parameter value in JSP like below code,
<s:property value="#parameters.reqVar1" />
但不起作用。
我看到参数在堆栈上下文中:
I see the parameter is in stack context:
我怎样才能在JSP中获取参数值?
How could I get the parameter value in JSP?
推荐答案
参数始终使用类型 Map< String,String []>
。你需要正确地输入参数,即
Parameters are always use a type Map<String, String[]>
. And you need to put parameter correctly, i.e.
aContext.getParameters().put("reqVar1", new String[] {"reqVar1-Value"});
并正确获取,即
<s:property value="%{#parameters.reqVar1[0]}" />
更好的方法是使用 params
拦截器包含在 defaultStack $ c中$ c>从请求中填充参数。
The better approach is to use params
interceptor that is included in thedefaultStack
to populate parameters from the request.
另见:
- How can we access request parameters passed into an Action
- How to use parameters in JSP
这篇关于我怎样才能在JSP中获取参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文