Load variable only once in struts 1 Action class -
I have Stractes Action Object instance that loads a variable from the property file. I want this to happen only for the first time, action is called, so it is read from its memory in further punishment, any sign? Thank you.
At first glance, I look at at least two ways of doing this:
1 - Read the value from the properties file and store it as a fixed field in its functional class, to load the bucket and read the value to a fixed starter. When your action class is loaded by JVM, you will get your value and later use it from there.
Public class increases yourAction action {Private Static String Value; Fixed {// value = load code here} ...}
Since it does not have access to Struts capabilities when it is loading I think you have to go something like your To read the value, the following:
ResourceBundle.getBundle ("Com / Something / Package / Bundle"). GetString ("some_key")
2 - Your price is set to the action instance and loaded with your constructor and later only use it:
public class increases yourAction action {Private string value; Public your action () {super (); // value = load code here} ...}
This will work because the string uses an action instance to complete all the requests, so all the requests will be viewed by your values ( I.e. the Straps Action class are threads not secure, they behave like servlets).
Comments
Post a Comment