velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Kevin Baynes" <kbay...@seagullsw.com>
Subject RE: context and images
Date Mon, 05 Aug 2002 15:42:05 GMT
I like to use the absolute path to my web applications in front of all my
static content, like "http://my.server/myWebApp/images/image.gif".

I like to determine this exact path and make it available as an Object to
the velocity context as something like $rooturlabsolute. That way I can
always write "$rooturlabsolute/images/image.gif", and modify the root url to
always be https:// or http://myServer:8282/ or whatever I know it needs to
be.

Here's my Servlet API 2.1+ code for determining it, you may not have to use
the fork if you don't have to support numerous containers:

		// build rooturlaboslute for use with images etc.
		String servletpath        = request.getServletPath();

		// fork for servlet API difference for getURL
		String requesturl = "";
		if (majorversion == 2 && minorversion >= 3) {
			requesturl     = request.getRequestURL().toString(); // 2.3 method
			//System.out.println("Administrator: handleRequest(): getRequestURL() 2.3
= " + requesturl);
		} else {
			// assume 2.1
			HttpUtils util = new HttpUtils();
			StringBuffer reqURL = util.getRequestURL(request);
			requesturl     = reqURL.toString();
			//System.out.println("Administrator: handleRequest(): getRequestURL() 2.1
= " + requesturl);
		}

		//System.out.println("Administrator: handleRequest(): getRequestURL() = "
+ requesturl);
		String rooturlabsolute    =
requesturl.substring(0,requesturl.indexOf(servletpath));

> -----Original Message-----
> From: Tomasz Mielnik [mailto:tomasz.mielnik@tdcinternet.pl]
> Sent: Monday, August 05, 2002 11:10 AM
> To: velocity-user@jakarta.apache.org
> Subject: context and images
>
>
> i know that this is a little offtopic but i'm going crazy with this.
> i have context in Tomcat "/webapp" and diferent servlets in this context
> (for example /webapp/servlet/showTemplate).
> in Velocity template i have a lot of pictures (pngs jpgs) but all with
> relativ path
>
> <img src="images/logo.png">
>
> when i call servlet i can se no pictures ofcoz sine they have relative
> paths.
> i dont want to add /webapp/images inforont of images form several
> reasons. is there a solution for this?
>
> TIA
>
> Tomasz Mielnik / Tdc Internet Polska
>
>
> --
> To unsubscribe, e-mail:
> <mailto:velocity-user-unsubscribe@jakarta.apache.org>
> For additional commands, e-mail:
> <mailto:velocity-user-help@jakarta.apache.org>


--
To unsubscribe, e-mail:   <mailto:velocity-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:velocity-user-help@jakarta.apache.org>


Mime
View raw message