<bdo id='hHmRt'></bdo><ul id='hHmRt'></ul>

    <legend id='hHmRt'><style id='hHmRt'><dir id='hHmRt'><q id='hHmRt'></q></dir></style></legend>

  1. <tfoot id='hHmRt'></tfoot>
    <i id='hHmRt'><tr id='hHmRt'><dt id='hHmRt'><q id='hHmRt'><span id='hHmRt'><b id='hHmRt'><form id='hHmRt'><ins id='hHmRt'></ins><ul id='hHmRt'></ul><sub id='hHmRt'></sub></form><legend id='hHmRt'></legend><bdo id='hHmRt'><pre id='hHmRt'><center id='hHmRt'></center></pre></bdo></b><th id='hHmRt'></th></span></q></dt></tr></i><div id='hHmRt'><tfoot id='hHmRt'></tfoot><dl id='hHmRt'><fieldset id='hHmRt'></fieldset></dl></div>

    1. <small id='hHmRt'></small><noframes id='hHmRt'>

    2. 升级到 struts 2.3.15.1 不会在操作类上设置 HashMap 值

      时间:2023-10-14

        • <bdo id='At4ia'></bdo><ul id='At4ia'></ul>
            <i id='At4ia'><tr id='At4ia'><dt id='At4ia'><q id='At4ia'><span id='At4ia'><b id='At4ia'><form id='At4ia'><ins id='At4ia'></ins><ul id='At4ia'></ul><sub id='At4ia'></sub></form><legend id='At4ia'></legend><bdo id='At4ia'><pre id='At4ia'><center id='At4ia'></center></pre></bdo></b><th id='At4ia'></th></span></q></dt></tr></i><div id='At4ia'><tfoot id='At4ia'></tfoot><dl id='At4ia'><fieldset id='At4ia'></fieldset></dl></div>

              <tbody id='At4ia'></tbody>
            <legend id='At4ia'><style id='At4ia'><dir id='At4ia'><q id='At4ia'></q></dir></style></legend>
          • <tfoot id='At4ia'></tfoot>
            1. <small id='At4ia'></small><noframes id='At4ia'>

                本文介绍了升级到 struts 2.3.15.1 不会在操作类上设置 HashMap 值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我从 2.1.6 升级到 2.3.15.1,因为最新版本中提供了安全修复程序.但是,现在表单字段值不会发布到 Action 类.基本上,当提交表单时,我将 JSP 中的 HashMap props 填充到 Action 类中.当我将 struts 版本升级到 2.3.15.1 时,这不起作用.没有代码更改.当我调试代码时,我注意到 setProps 方法没有被调用.这已经不允许了.有什么解决方法吗?一旦我恢复 struts 库的更改,一切都会完美.请帮忙.

                I upgraded from 2.1.6 to 2.3.15.1 because of the security fixes available in the latest version. However, now the form field values are not posted to the Action class. Basically, I populate the HashMap props from the JSP into the Action class, when the form is submitted. When I upgraded the struts version to 2.3.15.1 this does not work. There has been no code change. When I debugged the code, I noticed that the setProps method is not invoked. Is this not allowed anymore. Is there any workaround? As soon as I revert the struts library changes, everything works perfect. Please help.

                我的代码如下所示:

                动作类:

                    private Map<String, Wall> props;
                
                    public void prepare(){
                          //fill up props map here.
                        }
                    public String view(){
                        return INPUT;
                    }
                
                    public String save(){
                        myService.setProps(props);
                        return INPUT;
                    }
                
                    public void setProps(Map<String, Wall> props) {
                        this.props = props;
                    }
                
                    public Map<String, Wall> getProps() {
                        return props;
                    }
                

                JSP:

                <s:iterator value="props.entrySet()" id="prop" status="propStatus">
                    <s:textfield name="props['%{#prop.key}'].value" value="%{#prop.value.value}" />
                </s:iterator>
                

                推荐答案

                自 Struts 2.1.6 以来发生了巨大的变化.如果您没有明确告诉它这样做,Struts 2 将不会为您创建对象.prepare 方法在 params 拦截器将 props 设置为操作之前调用,并且您评论说您填充了地图

                There have been huge changes since Struts 2.1.6. Struts 2 will not create objects for you if you don't explicitly tell it to do. The prepare method calls before the params interceptor sets props to the action, and you commented that you populate the map

                //在此处填写道具图.

                //fill up props map here.

                毫不奇怪,Struts 不会调用该 setter setProps,因为它已经包含一个地图实例.因此,它只是调用 getProps.然后它应该将索引属性值设置为地图.但它不知道作为要转换为集合元素的对象的类型,以及它是否应该为元素创建一个新对象(如果它是 null).通过在 props 字段上添加注释,它应该可以解决在提交时填充地图的问题.

                not surprisingly, that Struts not call that setter setProps because it already contains a map instance. So, it simply calls getProps. Then it should set the indexed property values to the map. But it doesn't know a type of the object that is an element of the collection to convert to, and if it should create a new object for element if it's null. By putting annotations on the props field it should solve the problem populating a map on submit.

                @Element(value = Wall.class)
                @CreateIfNull(value = true)
                private Map<String, Wall> props = new HashMap<>();
                

                我猜它会自动确定的关键.如果您在 Action-conversion.properties

                I guess the key it will determine automatically. The same could be done if you specify it in Action-conversion.properties

                Element_props=Wall
                CreateIfNull_props=true
                

                接下来你的 JSP 可以被替换为

                Next your JSP could be replaced to

                <s:iterator value="props">
                    <s:textfield name="props['%{key}'].value" />
                </s:iterator>
                

                最后是你还没有发布的 Wall 类,应该是这样的

                And last the Wall class you haven't posted, should look like

                public class Wall {
                  String value;
                  //getter and setter here
                } 
                

                这篇关于升级到 struts 2.3.15.1 不会在操作类上设置 HashMap 值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:如何使用 Struts2 更改默认 JSP/模板位置 下一篇:如何使用 Struts 2 标签迭代 Set 元素

                相关文章

                • <bdo id='D5QQZ'></bdo><ul id='D5QQZ'></ul>

                1. <i id='D5QQZ'><tr id='D5QQZ'><dt id='D5QQZ'><q id='D5QQZ'><span id='D5QQZ'><b id='D5QQZ'><form id='D5QQZ'><ins id='D5QQZ'></ins><ul id='D5QQZ'></ul><sub id='D5QQZ'></sub></form><legend id='D5QQZ'></legend><bdo id='D5QQZ'><pre id='D5QQZ'><center id='D5QQZ'></center></pre></bdo></b><th id='D5QQZ'></th></span></q></dt></tr></i><div id='D5QQZ'><tfoot id='D5QQZ'></tfoot><dl id='D5QQZ'><fieldset id='D5QQZ'></fieldset></dl></div>
                    <legend id='D5QQZ'><style id='D5QQZ'><dir id='D5QQZ'><q id='D5QQZ'></q></dir></style></legend>

                    <tfoot id='D5QQZ'></tfoot>

                  1. <small id='D5QQZ'></small><noframes id='D5QQZ'>