• Post Reply Bookmark Topic Watch Topic
  • New Topic

getting the path of the base url

 
kourosh parsa
Ranch Hand
Posts: 35
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi. I have a data.json in my J2EE web app.
I need to load it either from local path when unit testing or from url when the server starts up.
so I've set it to get the local path by default and what I'm trying to do is that it is is running on a server, I'd like to change the path to a url.
Here is my code:

which works fine. The only issue is that I had to place this in the login page. Is there a way I can only set the path to the base url upon server start up?
Logically I should not even have to wait for a request so please let me know if you know a better way.
 
Joe Harry
Ranch Hand
Posts: 10128
3
Eclipse IDE Mac PPC Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have a look at the Servet's load-on-startup element in the web.xml.
 
kourosh parsa
Ranch Hand
Posts: 35
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks.
My understanding is that you're suggesting that I have a startup servlet and in the xml file I specify it to be a startup:


How would it know whether to run the get or the post handler?
 
Surendra Kumar
Ranch Hand
Posts: 236
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Whatever you want to do at servlet load time, put that in init() method. Not in post/get handlers.
 
kourosh parsa
Ranch Hand
Posts: 35
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks. I'll give it a try.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65519
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Or better yet, learn about context listeners.
 
kourosh parsa
Ranch Hand
Posts: 35
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The best I could do is:


I do not like hard coding the port like so. If anyone knows a way to avoid it, please let me know.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!