JSP中如何获取参数?

2024-01-28

这是我的行动execute() method,

@Override
public String execute() throws Exception {
    
    ActionContext aContext = ActionContext.getContext();        
    aContext.getParameters().put("reqVar1", "reqVar1-Value");
    
    return SUCCESS;
}

我想像下面的代码一样获取JSP中的参数值,

<s:property value="#parameters.reqVar1" />

但它不起作用。

我看到参数位于堆栈上下文中:

如何获取JSP中的参数值?


参数始终使用类型Map<String, String[]>。并且您需要正确输入参数,即

aContext.getParameters().put("reqVar1", new String[] {"reqVar1-Value"});

并得到正确的结果,即

<s:property value="%{#parameters.reqVar1[0]}" />

更好的方法是使用params拦截器 https://struts.apache.org/core-developers/parameters-interceptor.html包含在 defaultStack从请求中填充参数。

另请参阅:

  • 我们如何访问传递到 Action 中的请求参数 https://cwiki.apache.org/confluence/plugins/servlet/mobile?contentId=14182#content/view/13977
  • 如何在JSP中使用参数 https://struts.apache.org/tag-developers/jsp.html#request-parameter
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

JSP中如何获取参数? 的相关文章

随机推荐