【问题标题】:update to struts2.3.15.1 breaks dot notation in jsp对 struts2.3.15.1 的更新打破了 jsp 中的点表示法
【发布时间】:2013-11-11 21:26:36
【问题描述】:

出于安全目的,我们更新到 Struts 2.3.15.1。当我们这样做时,我们注意到我们失去了一些使用 jsp 中的点表示法设置值的能力。如果我们有一个采用 Foo 类的地图并且 Foo 有一个 Bar 类,那么我们之前已经成功地使用隐藏字段为 Foo 设置 Bar 类。当我们更新时,Bar 类现在显示为 null 而之前 Bar 类(在下面的示例中)将为 Foo 创建并赋予 12 的 id 值。我知道这类似于 2.3.15.1 上的问题未设置 hashmap 值,但该帖子中的建议已尝试但未成功:

[Upgrading to struts 2.3.15.1 does not set HashMap values on action class

是否需要在我们的 jsp 中使用某种语法来获取新版本 Struts 的先前结果?

类 Foo

private Bar bar;

private String name;

public Bar getBar(){

return bar;

}

public void setBar(Bar bar){

this.bar = bar;

}

public String getName(){

return name;

}

public void setName(String name){

this.name = name;

}

类栏

private int id

public int getId(){

return id;

}

public void setId(int id){

this.id = id;

}

Class ActionClass{

private Map<String, Foo> userInputMap;

public Map<String, Foo> getUserInputMap(){
return userInputMap;
}

public void setUserInputMap(Map<String, Foo>, userInputMap){
this.userInputMap = userInputMap;
}

}

input.jsp

<s:hidden name="foo.userInputMap<'first_map_key'>.bar.id" value="12" />

<s:textarea name="foo.userInputMap<'first_map_key'>.name />

【问题讨论】:

  • 为了成功的生活总是缩进代码。

标签: java jsp struts2


【解决方案1】:

想绕回去,原帖是我的同事。

我们终于找到了这个问题的答案。问题不是我们想的那样,问题是请求参数太长了。 S2-011(请参阅https://struts.apache.org/release/2.3.x/docs/s2-011.html)将请求参数长度减少到 100 个字符。

字段中的名称被用作请求参数,在某些情况下,我们的字段名称超过 120 个字符。

通过将以下代码放入我们的 struts.xml 文件,问题得到解决。

<interceptor-ref name="params">
      <param name="paramNameMaxLength">150</param>
</interceptor-ref>

【讨论】:

    【解决方案2】:
    <s:iterator value="userInputMap" >
        <s:hidden   name="userInputMap['%{key}'].bar.id" />
        <s:textarea name="userInputMap['%{key}'].name"   />
    </s:iterator>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-09-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-13
      • 2021-12-17
      • 2019-05-02
      相关资源
      最近更新 更多