You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by RXZ JLo <ru...@yahoo.com> on 2002/12/04 11:27:36 UTC

static url routing

my html files have long names like 
a_b_c_d_xyz213_e_f_g.html, a_b_c_d_pqr983_e_f_g.html

ie., they have a common prefix and suffix.

is it possible to have urls like
http://localhost:8080/myapp/html/xyz213
point to the first file above?

Note that I dont want to write a servlet for that,
only changes in web.xml or some other configurations.



__________________________________________________
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: static url routing

Posted by Mike W-M <mi...@ward-murphy.co.uk>.
I assume you've looked through all the elements available to you in web.xml.
(I can't think of any that might help, but I'm no authority!)
One (reasonably simple) solution would be to write yourself a servlet that
performs the mapping for you.  Assuming the root of the path remains
constant for your requests like this, map that to the servlet.
The servlet then has to examine the final part of the URL, lookup against
your mapping-list (which you should really load up from an XML file during
class-load, but you *could* hard code it), and then either redirect or
forward to your required resource.   (Redirect involves an extra round-trip
and will mean that the user sees a URL that ends with the real filename;
forwarding will leave the "original" URL in place.)

Mike.

----- Original Message -----
From: "RXZ JLo" <ru...@yahoo.com>
To: "Tomcat Users List" <to...@jakarta.apache.org>
Sent: Friday, December 06, 2002 9:50 AM
Subject: RE: static url routing



--- "Noel J. Bergman" <no...@devtech.com> wrote:
> > my html files have long names like
> > a_b_c_d_xyz213_e_f_g.html,
> a_b_c_d_pqr983_e_f_g.html
>
> > is it possible to have urls like
> > http://localhost:8080/myapp/html/xyz213
> > point to the first file above?
>
> You can use either a Filter, or mod_rewrite in
> Apache httpd.
>

I had a glance at javax.servlet.Filter - with this I
cannot avoid entering a servlet, which will then wont
be 'static' response.


> --- Noel
>

Thanks
rf

To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
For additional commands, e-mail:
<ma...@jakarta.apache.org>




--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: static url routing

Posted by "Noel J. Bergman" <no...@devtech.com>.
> --- "Noel J. Bergman" <no...@devtech.com> wrote:
> > my html files have long names like
> > a_b_c_d_xyz213_e_f_g.html,
> a_b_c_d_pqr983_e_f_g.html
>
> > is it possible to have urls like
> > http://localhost:8080/myapp/html/xyz213
> > point to the first file above?
>
> You can use either a Filter, or mod_rewrite in
> Apache httpd.
>

> I had a glance at javax.servlet.Filter - with this I
> cannot avoid entering a servlet, which will then wont
> be 'static' response.

<<shrug>> Something has to modify the request.  Personally, I don't do in
Tomcat what I can do in Apache, so I'd be using mod_rewrite for your task.
But since this is the tomcat mailing list, I mentioned a filter as an
option.

	--- Noel


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: RequestDispatcher scenarios ( was RE: static url routing)

Posted by "Craig R. McClanahan" <cr...@apache.org>.

On Thu, 12 Dec 2002, RXZ JLo wrote:

> >
> > If you're serving your own static content with your
> > own servlet, then you
> > could do this.  Using a Filter lets you use Tomcat's
> > standard static file
> > serving servlet with no modifications.
>
>
> It seems I am confused about how RequestDispatcher
> works. From what I understand I think using a
> RequestDispatcher from within a Servlet or a Filter,
> is same - the request is viewed as a fresh request
> appropriately handled by Tomcat. This means, when I
> use RequestDispatcher(static_url).forward()+return in
> a servlet, it is the tomcat that is serving the static
> url, and in the same way as directly requested static
> urls.
>
> "If you're serving your own static content with your
> own servlet, then you could do this." -- I want
> RequestDispatcher to handle serving the static content
> in my own servlet.

Your understanding of how request dispatchers work is essentially correct.
I was pointing out that it's *possible* to implement redirection to
standard static resources using a filter.  Using your own servlets to
handle the static resources is also possible - just make sure that the
URLs you forward to are mapped to your servlet.

>
> Please clarify.
> Thanks,
> rf.
>

Craig


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: RequestDispatcher scenarios ( was RE: static url routing)

Posted by RXZ JLo <ru...@yahoo.com>.
--- "Craig R. McClanahan" <cr...@apache.org> wrote:
> 
> 
> On Mon, 9 Dec 2002, RXZ JLo wrote:
> 
> > Date: Mon, 9 Dec 2002 03:21:25 -0800 (PST)
> > From: RXZ JLo <ru...@yahoo.com>
> > Reply-To: Tomcat Users List
> <to...@jakarta.apache.org>
> > To: Tomcat Users List
> <to...@jakarta.apache.org>
> > Subject: RequestDispatcher scenarios ( was RE:
> static url routing)
> >
> >
> > --- "Craig R. McClanahan" <cr...@apache.org>
> wrote:
> > > To do a redirect filter, then, you'd examine the
> > > request URI to determine
> > > what kind of remapping is needed, and then do a
> > > RequestDispatcher.forward() call to the remapped
> > > resource name.  After the
> > > forward returns (which means that the actual
> > > response has been created),
> > > simply return instead of calling
> chain.doFilter() to
> > > pass the request on.
> > >
> >
> > I am looking for various scenarios where
> > RequestDispatcher is used. When I searched the
> list, I
> > noticed that it can be used in a Servlet too. What
> > then is the difference between using it in a
> Filter
> > and using it in servlet? Can I just use it in the
> > Servlet to serve my purpose(of serving static
> > content)?
> >
> 
> If you're serving your own static content with your
> own servlet, then you
> could do this.  Using a Filter lets you use Tomcat's
> standard static file
> serving servlet with no modifications.


It seems I am confused about how RequestDispatcher
works. From what I understand I think using a
RequestDispatcher from within a Servlet or a Filter,
is same - the request is viewed as a fresh request
appropriately handled by Tomcat. This means, when I
use RequestDispatcher(static_url).forward()+return in
a servlet, it is the tomcat that is serving the static
url, and in the same way as directly requested static
urls.

"If you're serving your own static content with your
own servlet, then you could do this." -- I want
RequestDispatcher to handle serving the static content
in my own servlet.

Please clarify.
Thanks,
rf.

__________________________________________________
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: RequestDispatcher scenarios ( was RE: static url routing)

Posted by "Craig R. McClanahan" <cr...@apache.org>.

On Mon, 9 Dec 2002, RXZ JLo wrote:

> Date: Mon, 9 Dec 2002 03:21:25 -0800 (PST)
> From: RXZ JLo <ru...@yahoo.com>
> Reply-To: Tomcat Users List <to...@jakarta.apache.org>
> To: Tomcat Users List <to...@jakarta.apache.org>
> Subject: RequestDispatcher scenarios ( was RE: static url routing)
>
>
> --- "Craig R. McClanahan" <cr...@apache.org> wrote:
> > To do a redirect filter, then, you'd examine the
> > request URI to determine
> > what kind of remapping is needed, and then do a
> > RequestDispatcher.forward() call to the remapped
> > resource name.  After the
> > forward returns (which means that the actual
> > response has been created),
> > simply return instead of calling chain.doFilter() to
> > pass the request on.
> >
>
> I am looking for various scenarios where
> RequestDispatcher is used. When I searched the list, I
> noticed that it can be used in a Servlet too. What
> then is the difference between using it in a Filter
> and using it in servlet? Can I just use it in the
> Servlet to serve my purpose(of serving static
> content)?
>

If you're serving your own static content with your own servlet, then you
could do this.  Using a Filter lets you use Tomcat's standard static file
serving servlet with no modifications.

> Thank you
> rf.

Craig



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RequestDispatcher scenarios ( was RE: static url routing)

Posted by RXZ JLo <ru...@yahoo.com>.
--- "Craig R. McClanahan" <cr...@apache.org> wrote:
> To do a redirect filter, then, you'd examine the
> request URI to determine
> what kind of remapping is needed, and then do a
> RequestDispatcher.forward() call to the remapped
> resource name.  After the
> forward returns (which means that the actual
> response has been created),
> simply return instead of calling chain.doFilter() to
> pass the request on.
> 

I am looking for various scenarios where
RequestDispatcher is used. When I searched the list, I
noticed that it can be used in a Servlet too. What
then is the difference between using it in a Filter
and using it in servlet? Can I just use it in the
Servlet to serve my purpose(of serving static
content)?

Thank you
rf.



__________________________________________________
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: static url routing

Posted by "Craig R. McClanahan" <cr...@apache.org>.

On Sat, 7 Dec 2002, RXZ JLo wrote:

> Date: Sat, 7 Dec 2002 05:02:24 -0800 (PST)
> From: RXZ JLo <ru...@yahoo.com>
> Reply-To: Tomcat Users List <to...@jakarta.apache.org>
> To: Tomcat Users List <to...@jakarta.apache.org>
> Subject: RE: static url routing
>
>
> --- "Craig R. McClanahan" <cr...@apache.org> wrote:
> >
> >
> > You actually *can* avoid entering a servlet, so
> > Filter is a very practical
> > way to do "redirect" type things, especially in the
> > same webapp.
> >
> >
>
>
> Okay. Does mean I can use the Filter interface
> carefully instead of Servlet interface, and still act
> as a servlet?

You could actually do this if you wanted to.

> Is there any harm in doing this - is
> Filter too handled by the Servlet container in the
> same way as a servlet(for eg, load once and use same
> instance for all requests).

Yes, filters are instantiated by the container the first time they are
needed, and have init() and destroy() methods that are called at the
usual times, just like a Servlet.

I imagine that there might be small performance differences today (I know
there is one in Tomcat 4.x because of the way the FilterChain is managed)
simply because filters are new and the container vendors haven't
necessarily optimized as heavily as they have for servlets, but that's a
very transient sort of issue.

> Is the servlet interface redundant then or am I missing something here?

Interesting question.

For existing applications, the Servlet interface is by no means obsolete
-- the introduction of Filters lets you implement the Decorator design
pattern around your existing applications, and add customizations without
having to impact the existing code.

For new applications, it's basically feasible (but see below) to write
your entire application in terms of Filters, using filter mappings to
compose the processing units for a particular request using the Chain of
Responsibility design pattern.  (You see basically the same pattern inside
Tomcat 4, by the way, if you look at the way that Tomcat uses Valves to
implement much of its request processing functionality.)

This technique requires you to ensure that at least one of the Filters you
configure assumes responsibility for actually creating the response.  It
is also harder to learn Filters than Servlets because of the additional
concepts (what's a FilterChain?  when do I call chain.doFilter()?) -- and
these concepts are overkill in relatively simple applications.  Therefore
I think Servlet will stick around for a long time as a starting point
concept (at the minimum).

[The "see below" note] In Servlet 2.3, there is one fundamental limitation
to using Filters as a general purpose replacement for Servlets -- when you
use a RequestDispatcher.include() or RequestDispatcher.forward() call to
invoke an alternate servlet, filters associated with the alternate path
are *not* invoked.  Among other things, this makes filters less useful
than they could be in MVC-style architectures that flow requests through a
controller servlet.

In Servlet 2.4 (currently in proposed final draft state in the JCP, and
being implemented in Tomcat 5.0), this limitation is being addressed.
You'll have the ability to declare that filters matching the alternate
path are invoked on RequestDispatcher calls, as well as on the original
request mapping.

> thanks,
> rf.
>

Craig


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: static url routing

Posted by RXZ JLo <ru...@yahoo.com>.
--- "Craig R. McClanahan" <cr...@apache.org> wrote:
> 
> 
> You actually *can* avoid entering a servlet, so
> Filter is a very practical
> way to do "redirect" type things, especially in the
> same webapp.
> 
> 


Okay. Does mean I can use the Filter interface
carefully instead of Servlet interface, and still act
as a servlet? Is there any harm in doing this - is
Filter too handled by the Servlet container in the
same way as a servlet(for eg, load once and use same
instance for all requests). Is the servlet interface
redundant then or am I missing something here?

thanks,
rf.

__________________________________________________
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: static url routing

Posted by "Craig R. McClanahan" <cr...@apache.org>.

On Fri, 6 Dec 2002, RXZ JLo wrote:

> Date: Fri, 6 Dec 2002 01:50:31 -0800 (PST)
> From: RXZ JLo <ru...@yahoo.com>
> Reply-To: Tomcat Users List <to...@jakarta.apache.org>
> To: Tomcat Users List <to...@jakarta.apache.org>
> Subject: RE: static url routing
>
>
> --- "Noel J. Bergman" <no...@devtech.com> wrote:
> > > my html files have long names like
> > > a_b_c_d_xyz213_e_f_g.html,
> > a_b_c_d_pqr983_e_f_g.html
> >
> > > is it possible to have urls like
> > > http://localhost:8080/myapp/html/xyz213
> > > point to the first file above?
> >
> > You can use either a Filter, or mod_rewrite in
> > Apache httpd.
> >
>
> I had a glance at javax.servlet.Filter - with this I
> cannot avoid entering a servlet, which will then wont
> be 'static' response.
>

You actually *can* avoid entering a servlet, so Filter is a very practical
way to do "redirect" type things, especially in the same webapp.

The normal flow of a Filter's doFilter() method usually looks like this:

  ... do some preprocessing ...
  chain.doFilter(request, response);
  ... do some postprocessing ...

However, there is *no* requirement that you actually call the
chain.doFilter() method to pass the request on.  It's entirely legal for
your Filter to do something that creates the response and returns, instead
of forwarding the rest of the call.

To do a redirect filter, then, you'd examine the request URI to determine
what kind of remapping is needed, and then do a
RequestDispatcher.forward() call to the remapped resource name.  After the
forward returns (which means that the actual response has been created),
simply return instead of calling chain.doFilter() to pass the request on.

>
> > 	--- Noel
> >
>
> Thanks
> rf
>

Craig



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: static url routing

Posted by RXZ JLo <ru...@yahoo.com>.
--- "Noel J. Bergman" <no...@devtech.com> wrote:
> > my html files have long names like 
> > a_b_c_d_xyz213_e_f_g.html,
> a_b_c_d_pqr983_e_f_g.html
> 
> > is it possible to have urls like
> > http://localhost:8080/myapp/html/xyz213
> > point to the first file above?
> 
> You can use either a Filter, or mod_rewrite in
> Apache httpd.
> 

I had a glance at javax.servlet.Filter - with this I
cannot avoid entering a servlet, which will then wont
be 'static' response.


> 	--- Noel
> 

Thanks
rf

__________________________________________________
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: static url routing

Posted by "Noel J. Bergman" <no...@devtech.com>.
> my html files have long names like 
> a_b_c_d_xyz213_e_f_g.html, a_b_c_d_pqr983_e_f_g.html

> is it possible to have urls like
> http://localhost:8080/myapp/html/xyz213
> point to the first file above?

You can use either a Filter, or mod_rewrite in Apache httpd.

	--- Noel


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>