You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by davidZaz3 <da...@mailinator.com> on 2011/04/22 15:08:41 UTC

Struts 2 Interceptor Question

Can a Struts 2 interceptor change/add a request or session parameter?

I'm trying to write a Struts 2 Exception Handler which is executed whenever
there is an uncaught exception. To do that, I plan to use a custom
interceptor based on the existing Struts 2 ExceptionMappingInterceptor. My
custom interceptor needs to be able to send customized text to a jsp page
which is displayed to the user. For example, a unique incidentId number will
be displayed on the jsp page.

Inside my intercept method, I can access the AccessInvocation's
InvocationContext which contains the following methods:

Map - getParameters()
Map - getSession()
void - put(key, value)
Object - get(key)

I tried modifying the Map returned by getParameters() and getSession(). I
also tried using put(key, value). However, my changes were not visible on
the jsp page when I used these methods.

Is it possible to modify a request or session variable from an interceptor?
Is there a better way to load dynamic information into a struts
global-exception-mapping error page?

--
View this message in context: http://struts.1045723.n5.nabble.com/Struts-2-Interceptor-Question-tp4332934p4332934.html
Sent from the Struts - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Struts 2 Interceptor Question

Posted by Christian Grobmeier <gr...@gmail.com>.
> Can a Struts 2 interceptor change/add a request or session parameter?

Yes, and you can look at an example when you have the source and open:
com.opensymphony.xwork2.interceptor.ParametersInterceptor

> I'm trying to write a Struts 2 Exception Handler which is executed whenever
> there is an uncaught exception. To do that, I plan to use a custom
> interceptor based on the existing Struts 2 ExceptionMappingInterceptor. My
> custom interceptor needs to be able to send customized text to a jsp page
> which is displayed to the user. For example, a unique incidentId number will
> be displayed on the jsp page.
>
> Inside my intercept method, I can access the AccessInvocation's
> InvocationContext which contains the following methods:
>
> Map - getParameters()
> Map - getSession()
> void - put(key, value)
> Object - get(key)
>
> I tried modifying the Map returned by getParameters() and getSession(). I
> also tried using put(key, value). However, my changes were not visible on
> the jsp page when I used these methods.
> Is it possible to modify a request or session variable from an interceptor?
> Is there a better way to load dynamic information into a struts
> global-exception-mapping error page?

As far as I can see it is done inside setParameters and its done via
the ActionContext method. But I am not sure why your changes are not
reflected. Anyway, hope this class gives you some inspiration.

Cheers,
Christian

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org