Wildcards in <url-pattern>

E

Edward Patrick

Hello,

I would like to have one servlet serve all requests that do not
require any "processing". For example, CSS's, JPG's, etc.

I know I can accomlish this with an entry in WEB.XML:

<servlet-mapping>
<servlet-name>ForwardServlet</servlet-name>
<url-pattern>*.css</url-pattern>
</servlet-mapping>


However; here's my problem. Let's say a page has the following:

<LINK rel=stylesheet type="text/css" href="style.css">

Now, since there is no mapping then "style.css" must reside in the
root. However; I can have my servlet search for "style.css". Let's
say it finds it at "MyApp/ThisClient/style.css".

So, my servlet adds the path and then forwards it on.

However; since WEB.XML says "*.css", well, now my request with
"MyApp/ThisClient/style.css" gets caught too.

The result is an endless loop until the server dies.

Is there any way around this?

I want the css file caught by WEB.XML the first time, after I build
the full path, I just want to serve it.

Any help out there?

Thanks,
Ed
 
C

Chris Smith

Edward said:
However; here's my problem. Let's say a page has the following:

<LINK rel=stylesheet type="text/css" href="style.css">

Now, since there is no mapping then "style.css" must reside in the
root. However; I can have my servlet search for "style.css". Let's
say it finds it at "MyApp/ThisClient/style.css".

So, my servlet adds the path and then forwards it on.

However; since WEB.XML says "*.css", well, now my request with
"MyApp/ThisClient/style.css" gets caught too.

The result is an endless loop until the server dies.

Is there any way around this?

You could consider using a filter instead. The first time through,
you'd catch the request and set an attribute in it that it's being
handled. Every other time through, you'd see that attribute and pass it
right through.

--
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 
O

Ola Gustafsson

(e-mail address removed) (Edward Patrick) writes:

So, my servlet adds the path and then forwards it on.

However; since WEB.XML says "*.css", well, now my request with
"MyApp/ThisClient/style.css" gets caught too.

<snip>

Hi

When you say you forward it, I take it you mean that you use sendRedirect.
If that's the case, the easiest way to solve your problem is to use
a request-dispatcher to forward instead:

RequestDispatcher rd = request.getRequestDispatcher(
"MyApp/ThisClient/style.css");
rd.forward(request,response);

HTH
HAND
 

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

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top