tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Robin Curts <>
Subject Issue getting Context inside a servlet
Date Wed, 13 Oct 2004 13:26:10 GMT
What I am trying to accomplish:
I'm trying to build a servlet that I can get the DocBase with, so I'm 
trying to locate org.apache.catalina.Context from the servlet.

Tomcat Version: 5.0.28
Java Version: 1.4.2_05

What I'm doing:
I am implementing ContainerServlet and this works great when I run the 
servlet through a web application defined in 
$catalina.home/servers/webapps/<my_webapp>.  Pretty much in the same 
place as the manager servlet.  However when I run it as an installed WAR 
file I am getting a nasty null pointer exception (running from 

The issue:
setWrapper() is never getting called when I have this inside the 
$catalina.home/webapps/ directory tree... only when I have it in 
$catalina.home/server/ directory tree.  Any thoughts on this?  When this 
webapp goes live it will be installed as a WAR file and I won't be able 
to control what directory it is in.  Any thoughts?

Here is my servlet, pretty basic, just trying to find the Context and 
import org.apache.catalina.*;
import javax.servlet.http.*;
import javax.servlet.*;
import java.util.*;

public class Ctx extends HttpServlet implements ContainerServlet {

    Context context;
    Deployer deployer;
    Wrapper wrapper;
    public Ctx() {
        context = null;
        deployer = null;
        wrapper = null;
    public Wrapper getWrapper() {
        return wrapper;
    public void setWrapper(Wrapper wrapper) {
        this.wrapper = wrapper;
        try {
            context = (Context)wrapper.getParent();
            deployer = (Deployer)context.getParent();
        } catch (NullPointerException e) {
            context = null;
            deployer = null;
    public void destroy() {
        // do nothing   
    public void init() {
        // do nothing
    public void doPost(HttpServletRequest request, HttpServletResponse 
    throws IOException, ServletException {
        doGet(request, response);   
    public void doGet(HttpServletRequest request, HttpServletResponse 
    throws IOException, ServletException {
        PrintWriter out = response.getWriter();
        out.println("My Context Object: " + context);
        out.println("Doc Base: " + context.getDocBase());

 * Robin Curts
 * (813) 786-8634

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message