velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "David Esposito" <espos...@newnetco.com>
Subject feature suggestion
Date Tue, 06 Mar 2001 16:31:13 GMT
Can you have the init() method default to a "properties" init param in the
context if one is not defined in the servlet tag? That is, what I've done
for most of my application is put all of my parameters in the context ...
like so:

	<servlet>
		<servlet-name>Logout</servlet-name>
		<servlet-class>com.servlets.LogoutServlet</servlet-class>
		<init-param>
			<param-name>properties</param-name>
			<param-value>velocity.properties</param-value>
		</init-param>
		<init-param>
			<param-name>PROVIDER_URL</param-name>
			<param-value>localhost:5999</param-value>
		</init-param>
	</servlet>

	<servlet>
		<servlet-name>SessionExpired</servlet-name>
		<servlet-class>com.servlets.SessionExpiredServlet</servlet-class>
		<init-param>
			<param-name>properties</param-name>
			<param-value>velocity.properties</param-value>
		</init-param>
	</servlet>

	<context-param>
		<description>Location of Naming server</description>
		<param-name>PROVIDER_URL</param-name>
		<param-value>localhost:1099</param-value>
	</context-param>

	<context-param>
		<description>Location of Context factory</description>
		<param-name>INITIAL_CONTEXT_FACTORY</param-name>
		<param-value>org.jnp.interfaces.NamingContextFactory</param-value>
	</context-param>

	<context-param>
		<description>Prefix for naming packages</description>
		<param-name>URL_PKG_PREFIXES</param-name>
		<param-value>org.jboss.naming</param-value>
	</context-param>

Where it uses the localhost:5999 for the LogoutServlet and use the
localhost:1099 for the SessionExpiredServlet ... that would neaten up the
deployment descriptor as then I could put the velocity.properties value into
the context instead of needing it declared for each servlet ... I've used
this method in the past and it seems to work:

private String getInitParam(GenericServlet servlet, String parameterName)
{
	String retVal = null;

	//First check to see if the value was specified on a servlet-specific basis
	if(servlet.getServletConfig().getInitParameter(parameterName) != null)
		retVal = servlet.getServletConfig().getInitParameter(parameterName);
	//Else, let's see if its set on an context-wide basis
	else
		retVal = servlet.getServletContext().getInitParameter(parameterName);

	return retVal;
}


Mime
View raw message