velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Charles N. Harvey III" <charl...@alloy.com>
Subject RE: context and images
Date Mon, 05 Aug 2002 15:57:26 GMT
I do this in the web.xml file.

<servlet>
  <servlet-name>baseservlet</servlet-name>
  <servlet-class>com.mycompany.baseservlet</servlet-class>
  <init-param>
    <param-name>imagepath</param-name>
    <param-value>/mypath/</param-value>
  </init-param>
</servlet>


After reading that init param in the servlet I make that value available in
the context so I can
do this with my templates:

<img src="$img/extra/path/image.jpg" />


This works well for me because my company uses an image server, sometimes
our own and
sometimes from akami.  So I can change that url to be
"http://images.mycompany.com/images"
and it will then redirect all image requests to my image server.

Just my two cents.

Charlie

> -----Original Message-----
> From: Kevin Baynes [mailto:kbaynes@seagullsw.com]
> Sent: Monday, August 05, 2002 11:42 AM
> To: Velocity Users List
> Subject: RE: context and images
>
>
> 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>


--
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