How do I define an environment variable that can be accessed in all servlets in a Web application ?

A J2EE application may require one or more initialization parameters to be accessed by one or more servlets in a web application. An initialization parameter be for a context or for a specific servlet. The context level parameters can be accessed by any servlets in the web application.

a) To define a context parameter you have to add in the following in the web.xml as follows:

<context-param>
  <param-name>filedir</param-name>
  <param-value>/temp</param-value>
</context-param>

b)You have to use context.getInitParameter method to get the Context level parameter as in the following code:

javax.servlet.ServletContext context = getServletContext();
String fileDir = context.getInitParameter("filedir"); 
  • Bookmark "How do I define an environment variable that can be accessed in all servlets in a Web application ?" at del.icio.us
  • Bookmark "How do I define an environment variable that can be accessed in all servlets in a Web application ?" at Digg
  • Bookmark "How do I define an environment variable that can be accessed in all servlets in a Web application ?" at Ask
  • Bookmark "How do I define an environment variable that can be accessed in all servlets in a Web application ?" at Google
  • Bookmark "How do I define an environment variable that can be accessed in all servlets in a Web application ?" at StumbleUpon
  • Bookmark "How do I define an environment variable that can be accessed in all servlets in a Web application ?" at Technorati
  • Bookmark "How do I define an environment variable that can be accessed in all servlets in a Web application ?" at Live Bookmarks
  • Bookmark "How do I define an environment variable that can be accessed in all servlets in a Web application ?" at Yahoo! Myweb
  • Bookmark "How do I define an environment variable that can be accessed in all servlets in a Web application ?" at Facebook
  • Bookmark "How do I define an environment variable that can be accessed in all servlets in a Web application ?" at Yahoo! Bookmarks
  • Bookmark "How do I define an environment variable that can be accessed in all servlets in a Web application ?" at Twitter
  • Bookmark "How do I define an environment variable that can be accessed in all servlets in a Web application ?" at myAOL
 
web_server/oc4j/oc4j_variable.txt · Last modified: 2008/12/14 15:57 by gerardnico