tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mike Roest <tom...@blahz.org>
Subject Re: Question about context-param
Date Thu, 16 Jan 2003 20:37:18 GMT
Shapira, Yoav wrote:
> Howdy,
> 
> 
>>Sorry 2 different Contexts, and my brain was all messed up.  When I'm
>>refering to my Context
>>Constructor it's actually the main servlet constructor (which in our
> 
> app is
> 
>>PolarisContext).  Which
>>extends HttpServlet.
> 
> 
> OK, that makes a bit more sense.  Although a similar argument applies.
> Even though a servlet is a normal class, and you can create a
> constructor for it and do stuff in the constructor, you probably
> shouldn't.  Instead, stick with overriding Servlet methods, in this case
> init.  The container is required to make the servlet context parameters
> available to your servlet's init() method.  It's not required to make
> them available to your servlet's constructor.  So for portability and a
> little bit less of a headache, you're better off not writing a servlet
> constructor and moving the constructor code to the servlet's init()
> method.
> 
Ok that worked great. I don't get the exceptions anymore but for some reason it's not pulling
the 
params from the web.xml.  Any Ideas?

code:
try {
      username = this.getInitParameter("oracleUser");
      password = this.getInitParameter("oraclePass");
      System.out.println("user: "+username+"\npass: "+password);
} catch(Exception e) { e.printStackTrace(); }

web.xml:
<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE web-app
     PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"
     "http://java.sun.com/j2ee/dtds/web-app_2.2.dtd">

<web-app>
     <context-param>
     	<param-name>oraclePass</param-name>
     	<param-value>polaris</param-value>
     	</context-param>
     	<context-param>
     	<param-name>oracleUser</param-name>
     	<param-value>polaris</param-value>
     	</context-param>
     <servlet>
         <servlet-name>PolarisContext</servlet-name>
         <servlet-class>polaris.servlet.PolarisContext</servlet-class>
	<load-on-startup>1</load-on-startup>
     	
</servlet>
     	
	<security-constraint>
		<web-resource-collection>
			<web-resource-name>polaris</web-resource-name>
			<url-pattern>/servlet/*</url-pattern>
		</web-resource-collection>

	</security-constraint>


</web-app>




--
To unsubscribe, e-mail:   <mailto:tomcat-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:tomcat-user-help@jakarta.apache.org>


Mime
View raw message