This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes Servlets and the fly likes servlet mapping and image access Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "servlet mapping and image access" Watch "servlet mapping and image access" New topic

servlet mapping and image access

Pawanpreet Singh
Ranch Hand

Joined: Jun 12, 2005
Posts: 264

Hi Everybody,

I am facing some problem during servlet mapping and accessing images under same context.

I have one servlet controller only that dispatches the request to all handler classes. I do request like


Here in above path, parameter1 value is variable and controller and page1 tokens are fixed. So i cant decide a fix value for url-pattern.

For such case, i used value following value in url-pattern under <servlet-mapping>


By doing this, i have achieved my target, but one problem i am facing, that i have some images in under controller context, so how to get those, /* is making problem for that, suppose in my jsp, if i have image like
<img src="/controller/images/one.gif"/>, this request again goes to controller instead of displaying the image (/* problem).

Could any body help me to sort out this problem.

Thanks in advance.

Ben Souther

Joined: Dec 11, 2004
Posts: 13410

This is more of a general servlet question than a Tomcat specific one so I'm going to move it to the Servlets forum for you.

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Ben Souther

Joined: Dec 11, 2004
Posts: 13410

The URL pattern:

Tells the container that you want ALL requests to be handled by the specified servlet.

You may want to come up with a more specific pattern.
Struts came up with the *.do extension for this purpose.
Other people create a /servlet/* or /action/* directory structure for this.
I agree. Here's the link:
subject: servlet mapping and image access
jQuery in Action, 3rd edition