Wildcards in <url-pattern>

Discussion in 'Java' started by Edward Patrick, Feb 25, 2004.

  1. 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
    Edward Patrick, Feb 25, 2004
    #1
    1. Advertising

  2. Edward Patrick

    Chris Smith Guest

    Edward Patrick wrote:
    > 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
    Chris Smith, Feb 25, 2004
    #2
    1. Advertising

  3. (Edward Patrick) writes:

    <snip>

    > 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
    --
    Ola Gustafsson
    Ola Gustafsson, Feb 26, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Thomas F. O'Connell

    Negative Lookbehind and Wildcards

    Thomas F. O'Connell, Feb 27, 2004, in forum: Perl
    Replies:
    1
    Views:
    722
    Gunnar Hjalmarsson
    Feb 28, 2004
  2. DotNetJunkies User

    DataView filters with wildcards

    DotNetJunkies User, May 24, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    548
    DotNetJunkies User
    May 24, 2004
  3. msnews.microsoft.com
    Replies:
    0
    Views:
    1,152
    msnews.microsoft.com
    Jul 18, 2004
  4. Josh Martin
    Replies:
    6
    Views:
    1,859
    Josh Martin
    Nov 23, 2003
  5. Dale
    Replies:
    1
    Views:
    1,040
    Wendy S
    Jan 23, 2004
Loading...

Share This Page