tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Mike Curwen" <mi...@gb-im.com>
Subject RE: Retrieving the context path from a standalone class
Date Thu, 08 Jan 2004 16:14:20 GMT
> AFAIK there's no way to get the HTML that a JSP page would show 
> without an actual request.


Right, which is why we need the context path.

I think where we diverge is in our assesment of 'bad practice'. You had
mentioned trouble with getRealPath(). Incorrect placement of a method in
the API lead to some problems. Was using the API as it stood at the
time, a 'bad practice' or was it a bad API decision that lead to
problems. I think when something is deprecated, because it's later found
out to be 'stoopid' or problematic, that's a bad API that's been fixed.
>From the API:

Deprecated. As of Version 2.1 of the Java Servlet API, use
ServletContext.getRealPath(java.lang.String) instead
 
I find it kinda funny it got moved, rather than *re*moved. It's eventual
home is more than ironic in the context of this discussion. (If it was
in both places, and only one got removed, ignore what I just said).
 
All I'm saying is.. where's the bad practice in trying to obtain a
Context path from the ServletContext object? We can already do it from a
Request. I agree about the separation of app develop and deployer.  The
deployer should be able to deploy to ANY context, and we as the
developer shouldn't care about where.  But that's my point. We don't
want to hard code anything, we want to retrieve the appropriate value
for one of our processes that *does* care about what the value is.
Unless we go through a stupid hack, we're very limited in how we can
retrieve this information, run-time.  I argue for improved visibility of
a method. 

the hack(s) I've used:
Use an init-param, duplicating the information of context path, and no
problem, because I'm the deployer AND developer, so I know to set both
up correctly.

use a starup servlet to request a JSP page. The JSP page now has a
Request object. Obtain context path from there, and spin off your
standalone class from the JSP.
 
But after all, I've labelled those as 'hack'. It's all solved by having
the appropriate method on the appropriate object.  But then again, what
do I know about it, I'm not part of the JSR, and I haven't been around
since before JServ. 

But of course, this is OT by now, so I promise not to post again on this
topic. :)


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Mime
View raw message