Zaheer Baloch
Zaheer Baloch

Reputation: 536

How to access jsp/servlet implicit objects in Struts2 actions?

I need to some properties such as init params to all my actions. How can I access init parameters in my action classes. Or is there any way such that I can pass parameters to my actions. I could use .properties file but that would be for only one action. I need to define parameters for all actions.

Thanks in advance

Upvotes: 0

Views: 1236

Answers (1)

djna
djna

Reputation: 55907

Th ActionContext gives access to the ServletContext, that in turn gives access to init parameters defined in the Web Applications deployment decriptor.

Implication of passing parameters this way is that they are deployed in the app. Possibly you might prefer to take them from some externally, separately deployable source? In which case picking up a config file or reading from a database might give more flexibility.

This article describes an approach to externalising the config. It's clearly more work, and increased complexity, but I have found the flexibility to be useful.

Upvotes: 1

Related Questions