Wildcards in <url-pattern>

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Edward Patrick

    Wildcards in <url-pattern>

    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>ForwardSer vlet</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
  • Chris Smith

    #2
    Re: Wildcards in &lt;url-pattern&gt;

    Edward Patrick wrote:[color=blue]
    > 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?[/color]

    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.

    --

    The Easiest Way to Train Anyone... Anywhere.

    Chris Smith - Lead Software Developer/Technical Trainer
    MindIQ Corporation

    Comment

    • Ola Gustafsson

      #3
      Re: Wildcards in &lt;url-pattern&gt;

      EPatrick@alldat a.net (Edward Patrick) writes:

      <snip>
      [color=blue]
      > 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.[/color]

      <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:

      RequestDispatch er rd = request.getRequ estDispatcher(
      "MyApp/ThisClient/style.css");
      rd.forward(requ est,response);

      HTH
      HAND
      --
      Ola Gustafsson

      Comment

      Working...