• Post Reply Bookmark Topic Watch Topic
  • New Topic

Accessing elements of Web.xml in .Java file  RSS feed

 
Swapnil Gaurshettiwar
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We have developed a portal in JSP,now we have some URL's which are pointing to authentication servers.

we have made entries in web.xml and are accessing it in .JSP file with the help of

getServletConfig().getServletContext().getInitParameter("<param name>");

if we try to access it the same way in *.java files we cant

alternate way we found out is we have created a static class and made the entries there and accessing the class member.

Can anyone suggest any other option so that the entries should be in web.xml as they are easier to modify while environment migration as compare to entries in
a class file ?

thanks.
Swapnil G.
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Servlets that extend HttpServlet implement the ServletConfig interface. Through that you can retrieve servlet init parameters, and -by way of the getServletContext method- context parameters.

If you have Java classes besides servlets that need this information, I suggest that you have the servlets retrieve the required values and pass them to those classes.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!