Hi all,
I am trying to share an object from a servlet to a JSP by using the
getServletContext().setAttribute() method in the init() of my servlet. I am
able to return the context from the JSP page but am unable to retrieve the
attribute (getAttribute() returns null).
I have setup the Context in the Server.xml file to contain
crossContext="true" and override="true" for the jsp context. This allowed
me to get the context as a non-null object. The attribute name and case are
the same as in the setAttribute() statement. Also in the Servlet I am
calling super.init(ServletConfig) so I am pretty sure that the Attribute is
being added correctly. This technique worked in the 3.X versions of tomcat
but I have tried it on both 4.0.1 and 4.0.3 and am not making any progress.
If anyone has some experience with using a servlet context in a JSP I would
gladly take any advice.
Server.xml snippet:
<!--This is the Servlet Context -->
<Context path="/DBPoolingServer" docBase="DBPoolingServer"
reloadable="true" crossContext="true" debug="9" override="true"/>
<!--This is the Context for the JSP webapp-->
<Context path="/test" docBase="test"
reloadable="true" crossContext="true" debug="9" override="true"/>
Servlet web.xml mappings:
<servlet-mapping>
<servlet-name>dbpoolingservlet</servlet-name>
<url-pattern>/dbpoolingservlet</url-pattern>
</servlet-mapping>
Servlet init() snippet:
public void init(ServletConfig config) throws ServletException {
super.init(config);
mDBPoolHandler = new DBPoolingHandler();
mDBPoolHandler.initialize();
getServletContext().setAttribute("DBPool", mDBPoolHandler);
}
JSP Snippet:
ServletContext lContext =
application.getContext("/DBPoolingServer/dbpoolingservlet/*");
if (lContext != null) {
Object lHandler = lContext.getAttribute("DBPool");
if (lHandler != null) {
Object lConn = new String();
if (lConn !=null) {
out.println("Connected");
}else {
out.println("not connected");
}
} else {
out.println("lHandler = null");
}
} else {
out.println("Context = null");
}
The JSP example above returns a non-null lContext and then a null lHandler.
So the getAttribute() appears to be failing.
Any help would be appreciated.
Jeff
--
To unsubscribe: <mailto:[EMAIL PROTECTED]>
For additional commands: <mailto:[EMAIL PROTECTED]>
Troubles with the list: <mailto:[EMAIL PROTECTED]>