Displaying Images in Velocity Templates

M

mdh

I am trying to learn the mechanics of creating servlets using Apache
2.0.52 and Tomcat 5.0.28. I have a very simple servlet class based
upon VelocityServlet that has a basic loadConfiguration() method and a
handleRequest() method to handle POST/GET requests sent to the servlet
by the following web.xml mapping:

<servlet-mapping>
<servlet-name>FirstApp</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>

Of course, this sends ALL incoming requests from the browser for my
host to the servlet, including requests generated by <IMG
src="/images/mylogo.gif"> type tags in the HTML of pages being sent
back to the client. My servlet doesn't look for image references in
requests to call a special method to load and stream these resources
back to the client. I was hoping there was a simple way for static
content to be rendered directly by the Tomcat server engine rather
than being passed to my servlet. However, if I try to make the
<url-pattern> more specific like this

<servlet-mapping>
<servlet-name>FirstApp</servlet-name>
<url-pattern>/do*</url-pattern>
</servlet-mapping>

I get 404 errors from Tomcat back through Apache to the browser saying
"/do" cannot be found.

After looking through a few example Velocity template file pages on
the web and in the distribution, I thought the $link.URI() function in
Velocity Tools was the trick for doing this but my page just displays
a placeholder for my image and a View Source shows the unaltered text
of my login.vm file.

All of the examples in the variety of books I'm looking at are so
overly simplified that they only show pages being returned with no
embedded URL references to other images, etc. so the servlet side of
the example never has to explain how to do this.

Is there a common naming scheme and paradigm I should implement in my
web.xml file <servlet-mapping> to avoid having to include logic in my
servlet to handle reqeusts for image content? In effect, references
like the following

https://firstapp.mydomain.com/do?action=login
https://firstapp.mydomain.com/do?action=search
https://firstapp.mydomain.com/do?action=logout

would pass to my servlet for specific processing while HTML pages sent
back to the client with references such as

https://firstapp.mydomain.com/images/mylogo.gif
https://firstapp.mydomain.com/images/cautionsign.gif

would cause Tomcat itself to send these resources back to the client
browser without my servlet having to bother handling them.


stratfan @ mindspring.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,177
Latest member
OrderGlucea
Top