• Post Reply Bookmark Topic Watch Topic
  • New Topic

store config data in xml  RSS feed

 
icredes
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Newbie Here....

I want to be able to create bean classes that will operate as conneciton objects.

I wanto to be able to store connection variables in the web.xml file.

Is this ideal and how do you read the variables from within a class file....

maybe I should make another class just to read variables...

thanks
James
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66208
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can put info into web.xml in a few ways. If they are to be associated with a specific servlet, you would define when as init-param elements within the servlet declaration. You would then obtain them from the ServletConfig for the servlet.

If they are application wide, you can define them using context-param elements and get at them via the ServletContext.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66208
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the classes in which you want to use these values are independent of the UI (and hence without access to servlet information), you could consider the use of properties files for these values.
 
icredes
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
are there any examples I can refer to

I have downloaded a few apps from sourceforge to get an idea, but very few apps come with source files...
 
icredes
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
properties files would work I think...

how are those implimented?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66208
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check out the ServletConfig.getInitParam() and ServletContext.getInitParam() methods. They're pretty straight-forward.

There are also methods to return the names of all init/context params defined.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66208
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For properties files, look up ResourceBundle.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by James Todd:
are there any examples I can refer to

I have downloaded a few apps from sourceforge to get an idea, but very few apps come with source files...


http://simple.souther.us has example apps for both servlet and context init params.
 
icredes
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok... go it to work!

created ./webapps/app/WEB-INF/classes/applications.parameters



crated java bean ./webapps/app/WEB-INF/classes/com/Parameters.java


then anywhere else in the app


thanks for the help
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!