There must have been a change in Struts 2.1.2.
Here is an update to the after() method that uses the ActionContext session
map:
protected void after(ActionInvocation invocation, ValidationAware
validationAware)
throws Exception
{
Result result = invocation.getResult();
if (result instanceof ServletRedirectResult
|| result instanceof ServletActionRedirectResult)
{
Map session = invocation.getInvocationContext().getSession();
Collection actionErrors = validationAware.getActionErrors();
if (actionErrors != null && actionErrors.size() > 0)
{
session.put(ACTION_ERRORS_KEY, actionErrors);
}
Collection actionMessages = validationAware.getActionMessages();
if (actionMessages != null && actionMessages.size() > 0)
{
session.put(ACTION_MESSAGES_KEY, actionMessages);
}
Map fieldErrors = validationAware.getFieldErrors();
if (fieldErrors != null && fieldErrors.size() > 0)
{
session.put(FIELD_ERRORS_KEY, fieldErrors);
}
}
}
The full interceptor source can be found here:
http://glindholm.wordpress.com/2008/07/02/preserving-messages-across-a-redirect-in-struts-2/
Mead Lai wrote:
>
> "java.lang.UnsupportedOperationException: Don't use default servlet
> session".
> Just use the session from ActionContext, don't use the servlet's.
>
> protected Map<String,String> getSession() {
> return ActionContext.getContext().getSession();//from
> ActionContext
> here!
> }
>
> protected HttpServletRequest request(){
> return ServletActionContext.getRequest();
> }
>
>
> On Wed, Nov 5, 2008 at 12:05 PM, Narayana S <[EMAIL PROTECTED]>
> wrote:
>
>> Hi,
>>
>> i am using apache Tomcat 6.0.3, struts 2.1.2, and jdk 1.6. can any
>> one help me solving this issue?
>>
>> Thanks in advance.
>>
>> On Tue, Nov 4, 2008 at 7:06 PM, Greg Lindholm <[EMAIL PROTECTED]>
>> wrote:
>>
>> >
>> >
>> >
>> > Ganesh123 wrote:
>> > >
>> > > Excellent work. i am looking for the same solution. i tried
>> > > implementing your interceptor , but it is throwing exception ...
>> > > "java.lang.UnsupportedOperationException: Don't use default servlet
>> > > session".
>> > >
>> > > near session.setAttribute(ACTION_MESSAGES_KEY,actionMessages);
>> > >
>> > >
>> >
>> > Very strange, I've never seen a session where setAttribute() throws an
>> > UnsupportedOperationException. (And whats a "default servlet
>> session"?)
>> > I can only guess it's something to do with your container environment.
>> >
>> > You had better post your configuration information; platform,
>> container,
>> > cluster setup? etc. maybe someone on the list can help.
>> >
>> > Here are the relevant lines of code from the interceptor.
>> >
>> > ActionContext actionContext = invocation.getInvocationContext();
>> > HttpServletRequest request = (HttpServletRequest)
>> > actionContext.get(StrutsStatics.HTTP_REQUEST);
>> > HttpSession session = request.getSession(false);
>> > if (session != null)
>> > {
>> > ...
>> > Collection actionMessages = validationAware.getActionMessages();
>> > if (actionMessages != null && actionMessages.size() > 0)
>> > {
>> > session.setAttribute(ACTION_MESSAGES_KEY, actionMessages);
>> > }
>> > ...
>> > }
>> >
>
>
>
>
--
View this message in context:
http://www.nabble.com/-S2--Preserving-messages-across-a-Redirect-in-Struts-2-tp18245061p20343444.html
Sent from the Struts - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]