Struts2形式更新会话映射中的对象? [英] Struts2 form to update object in Session map?
问题描述
在我的构建动作中,我将一个对象放到会话图中。
InputField testField = new InputField();
testField.setName(testName);
testField.setValue(testValue);
sessionMap.put(TEST_FIELD,testField);
在JSP中,我想使用此对象来构建文本字段。
< s:textfield name =#session.TEST_FIELD.value/>
提交此表单后,我想用文本字段中的新值更新会话。
填入文本字段并提交表单后,这个'testResult'仍然包含对象生成时的原始值。
String testResult =((InputField)sessionMap.get(TEST_FIELD))。getValue();
>> testValue
我在哪里错了?
感谢!
您的操作应处理验证您的'测试字段值'并相应地设置会话中的值。 p>
您无法直接将值发布到会话中。如果可以的话,那将是一场安全噩梦。
In my build action, I have an object that I put into my session map.
InputField testField = new InputField();
testField.setName("testName");
testField.setValue("testValue");
sessionMap.put("TEST_FIELD", testField);
In the JSP, I want to build a textfield using this object.
<s:textfield name="#session.TEST_FIELD.value"/>
Upon submit of this form, I'd like to update the session with the new value from the textfield.
And after filling in the textfield and submitting the form it's a part of, this 'testResult' still contains the original value from when the object was built.
String testResult = ((InputField) sessionMap.get("TEST_FIELD")).getValue();
>> testValue
Where am I going wrong?
Thanks!
Your action should handle validating your 'test field value' and setting the value in the session accordingly.
You cannot post values directly into your session. If you could, that would be a security nightmare.
这篇关于Struts2形式更新会话映射中的对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!