You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by "Zacharias J. Beckman" <zb...@creativesun.com> on 2000/01/08 17:09:23 UTC

Possible to redirect "back" to Apache?

I'm wondering if it's possible to redirect a request back to Apache.

Here's a simple example. Apache has its various error handling pages. When I
try to invoke a servlet or JSP that doesn't exist, it is possible to send
the request "back" to Apache for handling rather than getting a Tomcat 404
error? I suspect this would require modification of Tomcat code, and is
probably a useful mod... but what's the general opinion?

The above is just an example. I realize that there is (probably) an XML
parameter that lets me customize the error message (at least, I hope there
is). But what I'm really investigating are more complex circumstances,
although having a standardized error handler would be nice, too.

Of course, a servlet can simply generate a redirect, but that's not what I'm
looking for. This is more of an integration level issue. I.e.: "If JSP page
not found, tell Apache to handle it" or "If exception XXX, go to Apache page
YYY." These would be nice "rules" to have Tomcat follow, but I don't know if
it is configurable...
--
Zacharias J. Beckman - zbeckman@creativesun.com - (U.S.) 305-281-8701
Creative Sun Inc., Publishing for the Internet - http://www.creativesun.com

Far better it is to dare mighty things, to win glorious triumphs, even
though checkered by failure, than to take rank with those poor spirits who
neither enjoy nor suffer much, because they live in the gray twilight that
knows neither victory nor defeat. -- Theodore Roosevelt


Re: Possible to redirect "back" to Apache?

Posted by Vincent-Olivier Arsenault <vi...@stria.com>.
it works fine for me:

in apache's .conf file:

ErrorDocument 404 /your_servlet_here

in context's web.xml

 <error-page>
 <error-code>404</error-code>
 <location>/your_servlet_here</location>
</error-page>


--vincent

----- Original Message ----- 
From: "Jason Hunter" <jh...@acm.org>
To: <to...@jakarta.apache.org>
Sent: Saturday, January 08, 2000 1:40 PM
Subject: Re: Possible to redirect "back" to Apache?


> Craig R. McClanahan wrote:
> > > it is possible to send
> > > the request "back" to Apache for handling rather than getting a
> > > Tomcat 404 error? 
> > 
> > The <error-page> element in the deployment descriptor lets 
> > you define the location (within your app) of the page to be displayed
> > on any particular HTTP status code, or any particular Java exception. 
> > I haven't checked whether Tomcat actually implements this or not, but
> > I'd rather see this used instead of the "link back to Apache"
> > approach.  
> 
> Tomcat implements the <error-page> element (and it worked when I last
> checked).  However, in the spirit of the spec I believe sendError(404)
> should generate an Apache 404, not a Tomcat 404.  The goal was to make
> servlets blend in with the server -- if you write a servlet to serve
> files and the servlet can't find a file, the client should receive a
> server-standard 404.  If Apache's the server, it's an Apache 404; if
> Tomcat's the server, it's a Tomcat 404.
> 
> My 2c.
> 
> -jh-
> 
> -- 
> Jason Hunter
> jhunter@acm.org
> Book:    http://www.servlets.com/book
> 2.0 to 2.1: http://www.javaworld.com/jw-12-1998/jw-12-servletapi.html
> 2.1 to 2.2: http://www.javaworld.com/jw-10-1999/jw-10-servletapi.html
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-dev-help@jakarta.apache.org
> 
> 


Re: Possible to redirect "back" to Apache?

Posted by Jason Hunter <jh...@acm.org>.
Craig R. McClanahan wrote:
> > it is possible to send
> > the request "back" to Apache for handling rather than getting a
> > Tomcat 404 error? 
> 
> The <error-page> element in the deployment descriptor lets 
> you define the location (within your app) of the page to be displayed
> on any particular HTTP status code, or any particular Java exception. 
> I haven't checked whether Tomcat actually implements this or not, but
> I'd rather see this used instead of the "link back to Apache"
> approach.  

Tomcat implements the <error-page> element (and it worked when I last
checked).  However, in the spirit of the spec I believe sendError(404)
should generate an Apache 404, not a Tomcat 404.  The goal was to make
servlets blend in with the server -- if you write a servlet to serve
files and the servlet can't find a file, the client should receive a
server-standard 404.  If Apache's the server, it's an Apache 404; if
Tomcat's the server, it's a Tomcat 404.

My 2c.

-jh-

-- 
Jason Hunter
jhunter@acm.org
Book:    http://www.servlets.com/book
2.0 to 2.1: http://www.javaworld.com/jw-12-1998/jw-12-servletapi.html
2.1 to 2.2: http://www.javaworld.com/jw-10-1999/jw-10-servletapi.html

Re: Possible to redirect "back" to Apache?

Posted by "Craig R. McClanahan" <cm...@mytownnet.com>.
"Zacharias J. Beckman" wrote:

> I'm wondering if it's possible to redirect a request back to Apache.
>

There's some interesting technical complexity in doing this, because it would
require modifying the protocol between Apache and Tomcat (which would also
affect Apache JServ).

>
> Here's a simple example. Apache has its various error handling pages. When I
> try to invoke a servlet or JSP that doesn't exist, it is possible to send
> the request "back" to Apache for handling rather than getting a Tomcat 404
> error? I suspect this would require modification of Tomcat code, and is
> probably a useful mod... but what's the general opinion?
>

The <error-page> element in the deployment descriptor lets you define the
location (within your app) of the page to be displayed on any particular HTTP
status code, or any particular Java exception.  I haven't checked whether
Tomcat actually implements this or not, but I'd rather see this used instead of
the "link back to Apache" approach.  That way, your app works even when you are
using Tomcat (or any other 2.2-compatible servlet engine) stand alone.

For more information about what is configurable about a web application for all
2.2 servlet containers, see the "Deployment Descriptor" chapter of the Servlet
API Specification, version 2.2, available at JavaSoft's web site.

Craig McClanahan



Re: Possible to redirect "back" to Apache?

Posted by co...@eng.sun.com.
"Zacharias J. Beckman" wrote:

> I'm wondering if it's possible to redirect a request back to Apache.

It is possible, and it should be done - I'm not sure I'll have the time
very soon, but it would be very usefull.

Solutions:
- just make a URL connection to Apache ( that will allow both
forward and include ) - but it's very inefficient ( TCP connections,
multiple parsings, possible loops, etc). It's easy to implement.

- change the protocol - that's the best solution but it's not easy
and require some C.

Costin