• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Getting a value from web.xml in run time

 
Fawad Ali
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello All,
I have these lines in web.xml.

<welcome-file-list>
<welcome-file>welcomeJSF.faces</welcome-file>
</welcome-file-list>

Now, is there anyway to get the value of <welcome-file></welcome-file> in a servlet.
 
Deepak Bala
Bartender
Posts: 6663
5
Firefox Browser Linux MyEclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why on earth would you need that value in a servlet at runtime ?
 
Fawad Ali
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Deepak,
I used a filter to hide the .jsp extension. In that filter I have specified if the URL points to the root then welcome.jsp file should be dispatched to the dispatcher. But I have hard coded the "welcome.jsp" name in the filter class. So if I do any change to web.xml. I will have to reflect it in my filter class. I want the filter class to be independent of web.xml. That is why I needed this.
 
Jimmy Clark
Ranch Hand
Posts: 2187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But I have hard coded the "welcome.jsp" name in the filter class. So if I do any change to web.xml. I will have to reflect it in my filter class. I want the filter class to be independent of web.xml. That is why I needed this.


Simply remove the hard-coding of the JSP filename from the filter class. You can store this information in a properties file and read the properties file in your filter class. Disregard the welcome-file element in web.xml.
 
Fawad Ali
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello James,
Thanks. That is a nice idea. But I wanted to go with the normal web.xml solution, so that in future if someone else is working on the project, he mau know where to find the welcome file.

 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Or use an XML parser to read the web.xml file. But I agree with James, storing it in a properties file is preferrable.
 
Fawad Ali
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot guys. I will choose one of them.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic