Re: Getting Context Parameters from server.xml
If you had String name = config.getInitParameter(companyName); it might work ;) HTH, Jon Michael Jones wrote: Hello- I'm trying to store some values in my server.xml and then get them with my Servlet. I followed the instructions at: http://jakarta.apache.org/tomcat/tomcat-4.0-doc/config/context.html under the Context Parameters section. In my servlet I got all init params and iterated over the enumeration. The parameter I defined in server.xml did not show up. Has anyone gotten this feature to work? Am I missing something? Here are a few code snippets: server.xml in the Context tag for my webapp Parameter name=companyName value=MyCompany override=false/ from my servlet ServletConfig config = getServletConfig(); String name = getInitParameter(companyName); System.err.println(CompanyName = ' + name + '); Enumeration enum = config.getInitParameterNames(); while(enum.hasMoreElements()) { System.err.println(enum.nextElement()); } Thanks- Michael - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Getting Context Parameters from server.xml
Why not set your context param in your webapps web.xml? Kind Regards Schalk Neethling Web Developer.Designer.Programmer.President Volume4.Development.Multimedia.Branding emotionalize.conceptualize.visualize.realize Tel: +27125468436 Fax: +27125468436 email:[EMAIL PROTECTED] web: www.volume4.com This message contains information that is considered to be sensitive or confidential and may not be forwarded or disclosed to any other party without the permission of the sender. If you received this message in error, please notify me immediately so that I can correct and delete the original email. Thank you. :: -Original Message- :: From: Jon Wingfield [mailto:[EMAIL PROTECTED] :: Sent: Thursday, March 25, 2004 12:22 PM :: To: Tomcat Users List :: Subject: Re: Getting Context Parameters from server.xml :: :: If you had :: String name = config.getInitParameter(companyName); :: it might work ;) :: :: HTH, :: :: Jon :: :: Michael Jones wrote: :: Hello- :: :: I'm trying to store some values in my server.xml and then get them with my :: Servlet. :: :: I followed the instructions at: :: http://jakarta.apache.org/tomcat/tomcat-4.0-doc/config/context.html :: under the Context Parameters section. :: :: In my servlet I got all init params and iterated over the enumeration. The :: parameter I defined in server.xml did not show up. :: :: Has anyone gotten this feature to work? Am I missing something? Here :: are a few code snippets: :: :: server.xml in the Context tag for my webapp :: Parameter name=companyName value=MyCompany override=false/ :: :: from my servlet :: ServletConfig config = getServletConfig(); :: String name = getInitParameter(companyName); :: System.err.println(CompanyName = ' + name + '); :: :: Enumeration enum = config.getInitParameterNames(); :: while(enum.hasMoreElements()) :: { :: System.err.println(enum.nextElement()); :: } :: :: :: Thanks- :: Michael :: :: :: - :: To unsubscribe, e-mail: [EMAIL PROTECTED] :: For additional commands, e-mail: [EMAIL PROTECTED] :: :: :: :: :: - :: To unsubscribe, e-mail: [EMAIL PROTECTED] :: For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Getting Context Parameters from server.xml
Oops. Sent too soon. That code would only work if your parameters were set up in you web.xml not server.xml ie context-param param-namecompanyName/param-name param-valueMyCompany/param-value /context-param The original code was looking up the servlet's init parameter, which should be defined: servlet servlet-nameparam-servlet/servlet-name servlet-classcom.MyCompany.ParamServlet/servlet-class init-param param-namecompanyName/param-name param-valueMyCompany/param-value /init-param /servlet These are portable ways (servlet spec compliant) to pass parameters to webapps. The Parameter tags within server.xml are related to Resources (Data Sources etc) and probably not what you want. Jon Jon Wingfield wrote: If you had String name = config.getInitParameter(companyName); it might work ;) HTH, Jon Michael Jones wrote: Hello- I'm trying to store some values in my server.xml and then get them with my Servlet. I followed the instructions at: http://jakarta.apache.org/tomcat/tomcat-4.0-doc/config/context.html under the Context Parameters section. In my servlet I got all init params and iterated over the enumeration. The parameter I defined in server.xml did not show up. Has anyone gotten this feature to work? Am I missing something? Here are a few code snippets: server.xml in the Context tag for my webapp Parameter name=companyName value=MyCompany override=false/ from my servlet ServletConfig config = getServletConfig(); String name = getInitParameter(companyName); System.err.println(CompanyName = ' + name + '); Enumeration enum = config.getInitParameterNames(); while(enum.hasMoreElements()) { System.err.println(enum.nextElement()); } Thanks- Michael - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Getting Context Parameters from server.xml
I think you want to use getServletContext().getInitParameter(companyName); There is a difference between a servlet init parameter (defined in web.xml) and a servlet context init parameter (defined in the context.xml or server.xml file) -Original Message- From: Jon Wingfield To: Tomcat Users List Sent: 25/03/2004 10:22 Subject: Re: Getting Context Parameters from server.xml If you had String name = config.getInitParameter(companyName); it might work ;) HTH, Jon Michael Jones wrote: Hello- I'm trying to store some values in my server.xml and then get them with my Servlet. I followed the instructions at: http://jakarta.apache.org/tomcat/tomcat-4.0-doc/config/context.html under the Context Parameters section. In my servlet I got all init params and iterated over the enumeration. The parameter I defined in server.xml did not show up. Has anyone gotten this feature to work? Am I missing something? Here are a few code snippets: server.xml in the Context tag for my webapp Parameter name=companyName value=MyCompany override=false/ from my servlet ServletConfig config = getServletConfig(); String name = getInitParameter(companyName); System.err.println(CompanyName = ' + name + '); Enumeration enum = config.getInitParameterNames(); while(enum.hasMoreElements()) { System.err.println(enum.nextElement()); } Thanks- Michael - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Getting Context Parameters from server.xml
Sweet that was the trick. Thanks alot for all of the responses. -Michael On Thu, 25 Mar 2004, Bodycombe, Andrew wrote: I think you want to use getServletContext().getInitParameter(companyName); There is a difference between a servlet init parameter (defined in web.xml) and a servlet context init parameter (defined in the context.xml or server.xml file) - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]