java - Best Practice? Where do I put configuration parameters for my own application in Struts2? -


In the Java Servlet, & lt; Context-param> gt; . In desktop applications, we generally define our own configuration file.

Where should I put the configuration parameters for my Struts2 app? For example, my application has to set the time frame for user input, or save and read any stored files anywhere, or users can type incorrect passwords, maximum time I want to configure those things.

How are people usually treated in the applications of Stratus 2? Any best practice?

If you are familiar with the ServletContext approach, then you have mentioned, You can stick with it in your web.xml , just copy your & lt; Context-param & gt; Add s.

Then, to get ServletContext in your works, just execute ServletContextAware and it will automatically be injected for you.

Here is a brief example:

web.xml
  & lt; Context param & gt; & Lt; Ultimate Name & gt; SomeSetting & lt; / Lastname & gt; & Lt; Ultimate Price & gt; SomeValue & lt; / Super-valued & gt; & Lt; / Reference param & gt;   

Your work
  The Public Class YourAction ActionSupport Component Extends ServletContextAware {Private ServletContext servletContext; Execute an override public string () Exception {strings some value = (string) subnetcontext.GetAttrite ("some setting"); Return success; } @ Override Public Wide Setserve Context (Last Serial Contact Reference) {this.servletContext = servletContext; }}    

Comments

Popular posts from this blog

mysql - BLOB/TEXT column 'value' used in key specification without a key length -

c# - Using Vici cool Storage with monodroid -

python - referencing a variable in another function? -