Struts2形式更新会话映射中的对象? [英] Struts2 form to update object in Session map?

查看:123
本文介绍了Struts2形式更新会话映射中的对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的构建动作中,我将一个对象放到会话图中。

  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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆