I am having problem setting up tomcat context variable.
I have tried:
-
in web.xml in root folder(note: it’s not the one in conf folder)
I tried adding context-param, not work, this did not change anything, the context variable is still null<context-param> <param-name>testname</param-name> <param-value>testvalue</param-value> </context-param> -
using servlet getServletContext.setAttribute(“test”,”ok”) to set variable, it does not work either, the variable just stay null all the time.
-
i have tried to add crossContext=true in server.xml (even though i only have one webapp), it does not work.
so any suggestions?
Thanks
You need to add the context parameter to the
/WEB-INF/web.xmlof your webapp, not one “in root folder” wherever that is.You need to get it by
ServletContext#getInitParameter():The
ServletContext#set/getAttribute()sets/gets attributes in the application scope. They are not related to context parameters.