To get the request you can just implement RequestAware interface which you can provide a setRequest(Map) method and the interceptors will set the request to whatever local Map you have in your action.
To get the session you can just implement SessionAware interface which you can provide a setSession(Map) method and the interceptors will set the session to whatever local Map you have in your action.
That should answer your original question, but I'm not sure what you are trying to do but you might actually be able to write a custom interceptor to do whatever it is you are trying to do.
Joined: Dec 09, 2010
Thanks for your reply. SessionAware and RequestAware seem to be specific to Struts 2. I forgot to mention that it is Struts 1.
My problem is this: I need to internationalize an application with ResourceBundles (.properties files). I don't know this application very well yet, neither Struts. There is a general myResources.properties file It is configured in struts-config:
myResources properties file contains german language strings. It works fine with JSPs, using <bean:message>. Now I have created a Resource file for polish language and placed it in the same directory: myResources_pl.properties. Just in case I also created myResources_pl_PL.properties.
In my browser I have set polish locale and removed all others. In the HTTP header the browser sends:
And added a tag to the JSP which I use for testing:
Now,when building the application and running it, it still displays strings from myResources properties when using:
myResources_pl.properties is ignored unfortunately. Then I put this code inside a custom tag (extends TagSupport) and printed out the "key" string which DOES display the string from the pl_PL file:
So, Struts does retrieve the polish locale from the request and it can select the localized Resource bundle.
Now, the problem remains that when printing something with <bean:message/> those strings still come from the myResource.properties.
As a last resort I thought about accessing the Action.LOCALE_KEY somehow and change it programatically, maybe by overriding the ActionServlet.init method. So I was asking for help with accessing session and request from this method although I can't believe that something like this really needs to be done.
Joined: Dec 09, 2010
I am happy that this was solved. The locallized properties files also needed to be copied on deployment. Becauses they were missing, Struts defaulted to the base file.
subject: How to access the request from an ActionServlet?