tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Geoff Soutter" <ge...@whitewolf.com.au>
Subject Re: ContextPath, ServletPath and backwards compatibility
Date Thu, 18 Nov 1999 02:31:26 GMT
Seems to me the "fix" here is don't be "lazy" and try and run it in the
/examples context. As long as you run it in the / context you'll be fine.

Seems like quite a reasonable limitation to me, and I doubt the servlet gods
would agree to change the API now...

Cheers

Geoff

-----Original Message-----
From: ja@almery.com <ja@almery.com>
To: tomcat-dev@jakarta.apache.org <tomcat-dev@jakarta.apache.org>
Date: Thursday, 18 November 1999 13:05
Subject: ContextPath, ServletPath and backwards compatibility


>Hey all,
>
>I seem to recall that issues surrounding this topic have recently been
>discussed, but I am unaware of any archives for the Jakarta lists, nor
>did I save any of the discussions.  Apologies if this is redundant.
>
>Recently, I got Turbine to run on Tomcat.  The main problem (so far)
>resulted from the use in Turbine of the
>HttpServletRequest.getServletPath().  I lazily placed Turbine inside
>the /examples context.  Turbine uses the getServletPath() method to
>figure out how it was called, and builds its response from that
>information.
>
>As a result, under Tomcat, Turbine kept dropping the "/examples" part
>of the URL (since getServletPath() doesn't return the context part in
>Tomcat).  Naturally, this caused Turbine to break.
>
>However, according to the spec, Tomcat seems to be behaving correctly.
>
>The "obvious fix" is heinous, and goes something like this:
>
>     // Allow Turbine to work with both 2.2 and 2.0 Servlet API
>     Class clazz = req.getClass();
>     try {
> java.lang.reflect.Method meth =
>                    clazz.getDeclaredMethod("getContextPath", null);
> data.scriptName = (String)meth.invoke(req, null);
>     } catch (Exception ex) {}
>     data.scriptName += req.getServletPath();
>
>This is very unpleasant and inefficient.
>
>I suppose I would have argued that the getServletPath() method should
>have been backwards compatible, behaving like it did in the 2.0 JSDK,
>and returning the "full" servlet path, context included.  One could
>then trivially obtain the non-context part by getting a substring.  As
>it is, this new behaviour seems likely to break many applications, and
>force ugly, inefficient hacks to make them compatible with the
>different API versions.
>
>I suppose, however, that it may be possible to change Turbine in such
>a way that the above hack is not necessary.  I currently don't know
>how to do that, though.
>
>Comments?
>
>Jay
>--
>Jay Doane | doane@acm.org
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: tomcat-dev-help@jakarta.apache.org
>
>


Mime
View raw message