Struts2 form to update object in Session map?

2019-08-23 10:56发布

问题:

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!

回答1:

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.