> From: behofmann [mailto:behofm...@gmail.com]
> Subject: Re: Forwarding from one Context to another
> 
> When trying to forward my .jsp to another <Context> in Tomcat 
> 6.0.18 using the following code, I get the following error:
>
>       ServletContext appContext = ServletContext.getContext( "/dev" );
>
> Error ==> non-static method getContext(java.lang.String) cannot be
> referenced from a static context

That message seems pretty self-explanatory: you're trying to call getContext() 
as a static method when it isn't static; you must use an instance of 
ServletContext.

> The following code compiles, but only forwards my new <Context> (/dev)
> appended to the SAME CONTEXT (/filter) as /filter/dev.
>
>       ServletContext appContext = getServletContext();

Which is what it's defined to do: you called getServletContext() with no 
arguments, so it returns the current ServletContext; you need to read the 
Servlet API spec:
http://java.sun.com/products/servlet/2.5/docs/servlet-2_5-mr2/index.html

If you want to reference the /dev webapp, code it like this:

    ServletContext appContext = getServletContext().getContext("/dev");

The above assumes you're making the call from a class that extends HttpServlet.

> I already added crossContext="true" to context.xml for both the
> original and new <Context>.

It won't hurt in the target <Context>, but it does nothing useful for you.  It 
only counts for the <Context> from which the forward originates.

 - Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY 
MATERIAL and is thus for use only by the intended recipient. If you received 
this in error, please contact the sender and delete the e-mail and its 
attachments from all computers.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org

Reply via email to