[prev in list] [next in list] [prev in thread] [next in thread] 

List:       velocity-user
Subject:    Re: Images in Templates
From:       Simon Christian <simon () stoutstick ! com>
Date:       2003-10-28 9:29:57
[Download RAW message or body]

Hi,

Kai O wrote:
> Hi,
> 
> thanks for your help. I experimentated around a bit with your suggestions
> but I think the general problem is somewhere else. The imagepath I use in my
> template seems to be correct (in my case
> http://127.0.0.1:800/test/eclipse.jpg) But what happens if the browser
> requests that image? I think that every request that starts with /..../test
> is handled by my servlet, so the browser never gets that image. So can I
> somehow tell the servlet that it should return an image if an image request
> comes in?

It's quite possible you have your servlet container set to map all 
requests within the webapp path to the servlet, when more likely you 
only want to map .vm requests to it. Do you have a section like this in 
your web.xml?

   <servlet-mapping>
     <servlet-name>myServlet</servlet-name>
     <url-pattern>*.vm</url-pattern>
   </servlet-mapping>

- simon


> 
> Regards
> 
> Kai
> 
> ----- Original Message -----
> From: <Christoph.Reck@dlr.de>
> To: "Velocity Users List" <velocity-user@jakarta.apache.org>
> Sent: Monday, October 27, 2003 11:19 AM
> Subject: Re: Images in Templates
> 
> 
> 
>>Hi,
>>
>>Kai O wrote:
>>
>>>Hi,
>>>
>>>i'm a real newbie to velocity so i'm sorry for any silly questions ;-)
>>>
>>>I have a tomcat server running and I have a java servlet which uses
>>>some template files. So my simple question is how do I include jpegs
>>>in my .vm files? If I just use them in html syntax like
>>><img src="test.jpg"></img> it doesn't work (the jpg has been copied
>>>to my tomcat\webapps\mywebapp folder).
>>
>>This is a simple webserver and servlet container issue. If you just say
>><img src="test.jpg">, your browser tries to locate the image from the
>>same location your page was requested from, probably something like
>>   http://yourserver:8080/mywebapp/yourVelocityServlet/yourTemplate.vm
>>so your browser was excpecting the image to be at:
>>   http://yourserver:8080/mywebapp/yourVelocityServlet/test.jpg
>>which did not work since your velocity servlet probably does not
>>know anything about images (must have been logged by the velocity
>>servlet).
>>
>>So you need to do something like:
>><img src="/mywebapp/test.jpg">
>>
>>Note that you can get the WEBAPP name from the servlet container,
>>and automate this using a macro in velocity (this is untested code,
>>please reply if it worked or what you did to make it work to help
>>others):
>>#macro( IMGURL $imgName )$request.ContextPath/$imgName#end
>>and use it:
>><img src="#IMGURL('test.jpg')">
>>
>>Normally you would place images in a subdirectory named "images"
>>of the webapp, or globally in the servlet container (see the location
>>of the tomcat images).
>>
>>NOTE: in tomcat versions 3.X I had problems with getContextPath()
>>not working when it was the first call creating the session. Since
>>then I made the webapp name configurable, so I have no idea if it
>>still does not work in Tomcat 4.1.X. It is good practice not to
>>hardwire the webapp name neiter in the templates nor in the application,
>>which allows reinstantiating the webapp under different names/locations.
>>I have wasted hours in searching/replacing hardwired webapp names in
>>colegues code to be able to relocate or reuse existing code.
>>
>>
>>>I have found something about #include, #parse and \pict in the archives
> 
> but I don't get what I want. If I use #include I get the image as text
> output in my html file.
> 
>>>So thanks for any help.
>>>
>>>Kai.
>>
>>--
>>:) Christoph Reck
>>
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
>>For additional commands, e-mail: velocity-user-help@jakarta.apache.org
>>
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
> 


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

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic