【问题标题】:How could I get a parameter in JSP?如何在 JSP 中获取参数?
【发布时间】:2013-07-26 07:20:05
【问题描述】:

这是我的操作execute()方法,

@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中如何获取参数值?

【问题讨论】:

  • 你为什么要那样做?使用 getter 和 setter 创建属性并使用它。
  • &lt;s:property value="#parameters.reqVar1" /&gt; 应该是&lt;s:property value="%{#parameters.reqVar1}" /&gt;

标签: java jsp struts2 jsp-tags ognl


【解决方案1】:

参数始终使用Map&lt;String, String[]&gt; 类型。而且您需要正确放置参数,即

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

并正确获取,即

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

更好的方法是使用包含在 defaultStack 中的params interceptor 从请求中填充参数。

另见:

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-25
    • 1970-01-01
    • 2010-12-25
    • 1970-01-01
    相关资源
    最近更新 更多