Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Settings Class  RSS feed

 
Kevin Tucker
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All

Is there such thing as creating a settings class like I have seen in Php?
A core class which holds Static variables as settings for the rest of the webapp

It seems like most of this stuff goes in the web.xml file with Java

Just looking for some opinions on this

Cheers
Kevin
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66184
146
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, you could create context parameters in the deployment descriptor.

Or, you could use a context listener to place app-wide values in application context.

Or, use a properties file.

Or, use a database.

Or....

Which route makes the most sense depends upon more information than you have disclosed.
 
Kevin Tucker
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Thanks for the reply.

Sorry to be rather vague, I am new to Servlets and JSP but not to Java.
I kinda have early stage questions I need to ask, and then hopefully I can pick up on the details myself through further reading.
Just need a nudge in the right direction, which I think you have now given me.

I have coded in Java for a little while for GUI apps, but mainly in Php for Webapps.
I am keen to use my Java knowledge across the board to further improve my skills & knowledge, so would like to move away from Php entirely eventually.

In Php I use a class to define static app wide variables such as DOCUMENT_ROOT, EMAIL_DEFAULT_TO, WEBSITE_URL etc etc
So I just call these in where required and only have to edit these at one place in the WebApp if required, not have to go through all the classes and code.
Was looking for something similar in Java

Regards
Kevin

 
Vijitha Kumara
Saloon Keeper
Posts: 3997
42
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As Bear suggested it depends on the scope/requirement you want them to be placed. There are runtime scopes like request, session, context etc.. and other ways like using properties files as well. But it all depends.
 
Vijitha Kumara
Saloon Keeper
Posts: 3997
42
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And Welcome to JavaRanch, Kevin
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66184
146
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In some projects, I have stored such values in the DB, fetched them in a context listener, and stored them in the application context where they are available to all aspects of the presentation layer.

For projects where the DB is not appropriate, I've stored the values in a properties file rather than a DB.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!