jakarta-cactus-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Bryan Cornies <bryan.corn...@sjrb.ca>
Subject Getting Initialization Parameters from web.xml
Date Thu, 08 Jun 2006 17:56:21 GMT
Hi,

I am trying to test a servlet which contains an init() method which
grabs a handful of initialization parameters from the web.xml file.  It
looks like:

public void init() throws ServletException 
{
	// Initialize servlet 
	ServletConfig config = getServletConfig();
      
	// Grab parameter values from web.xml
	param1 = config.getInitParameter("param1");
	param2 = config.getInitParameter("param2");
	
	etc...
}

I understand that, from reading the documention, I need to call init on
the servlet and pass it the ServletConfigWrapper member variable.  Thus,
my test method looks like:

public void testDoPost()
{
	MyServlet servlet = new MyServlet();
	servlet.init(config);
      servlet.doPost(request, response);
}

The problem is, unless I explicitly call setInitializationParameter() in
testDoPost(), which just redundently sets the same parameters that are
already specified in web.xml, the servlet cannot find them when it calls
config.getInitParameter().  It works fine when I send a POST to the
servlet through a jsp.

I feel like I'm missing a key concept somewhere.  I've spent the last
couple of days trying anything I could think of with no luck.  Any
assistance would be greatly appreciated!

Cheers,
Bryan

Mime
View raw message