You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@turbine.apache.org by Craig McDaniel <cr...@nplus1.net> on 2002/02/12 18:05:39 UTC

Pretty URL's in Turbine?

OK, this is really annoying, but I have a client who wants his URL's to
look nice and friendly. I have ruled out using mod_rewrite in apache. I
would like to be able to have

http://server/news.html

execute my News screen class in Turbine (i.e.,
http://server/servlet/Turbine/template/news.html)

Is there a clean way to do this? I have been looking at Filters, but I
am not sure if that will work in this case. I have also considered
writing a servlet to forward the request (via RequestDispatcher) to
Turbine. Are there any pitfalls to this method? 

Here are some other examples of the mappings that I will need to
implement:

* http://server/blah/foo.html/action/Update/var/123
-> http://server/servlet/Turbine/template/blah/foo.html/action/Update/var/123

* http://server/images/image.jpg
This one will be left alone. Basically, any request for a template
(*.html or *.vm) or action will be handled by Turbine, while other 
requests will be assumed to be static (I am hoping there will never be
any JSP).

I realize that by doing this, TemplateLink may not work properly, and I
may have to write my own if I want to use the link tool in my templates.

Thanks.
-- 
\ Craig Patrick McDaniel
/_\ Software Engineer
/_/_\ n + 1, Inc.
/_/_/_\ craigm@nplus1.net
/_/_/_/_\ (502) 479-5557

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


Re: Pretty URL's in Turbine?

Posted by Luke Holden <al...@prodigy.net>.
> http://server/news.html
>
> execute my News screen class in Turbine (i.e.,
> http://server/servlet/Turbine/template/news.html)

What I do is pretty simple.. I set up a jsp page with a jsp:forward tag. 

So for example.. you might have

http://server/news.jsp

which contains the following:

<jsp:forward page="servlet/Turbine/template/news.html" />


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


Re: Pretty URL's in Turbine?

Posted by Rodney Schneider <rl...@arcalink.com>.
On Friday 15 February 2002 02:20 am, you wrote:
> On Wed, Feb 13, 2002 at 12:41:46PM +1100, Rodney Schneider wrote:
> > On Wednesday 13 February 2002 04:15 am, you wrote:
> > Other options to consider for making pretty URLs work with Turbine
> > include:
>
> <snip>
>
> > 4. You could write your own servlet to replace the default servlet for
> > the webapp, using the default servlet mapping, /.  PATH_INFO will also be
> > null in this scenario.  Your custom servlet could map pretty URLs to the
> > ugly Turbine URLs by using a RequestDispatcher.forward().  Check out the
> > servlet invoker that comes with Tomcat for ideas on how to implement
> > this.
>
> </snip>
>
> OK, #4 sounds like a lot of work, and I am not going to pursue it at
> this time. So my next question comes out of curiosity. Why is PATH_INFO
> null in this scenario? Tomcat's default servlet doesn't lose the
> PATH_INFO, so why would a replacement?

I should have mentioned that I only work with Servlet API 2.3 compliant 
containers, such as Tomcat 4.x.  Tomcat's default servlet actually uses 
request.getServletPath() to extract the path, rather than 
request.getPathInfo() which would return null.  I am not sure what the 
situation is for Tomcat 3.x or other Servlet API 2.2 containers.

Regards,

-- Rodney

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


Re: Pretty URL's in Turbine?

Posted by Craig McDaniel <cr...@nplus1.net>.
On Wed, Feb 13, 2002 at 12:41:46PM +1100, Rodney Schneider wrote:
> On Wednesday 13 February 2002 04:15 am, you wrote:
> Other options to consider for making pretty URLs work with Turbine include:
<snip>
> 4. You could write your own servlet to replace the default servlet for the
>    webapp, using the default servlet mapping, /.  PATH_INFO will also be null
>    in this scenario.  Your custom servlet could map pretty URLs to the ugly
>    Turbine URLs by using a RequestDispatcher.forward().  Check out the
>    servlet invoker that comes with Tomcat for ideas on how to implement this.
</snip>

OK, #4 sounds like a lot of work, and I am not going to pursue it at
this time. So my next question comes out of curiosity. Why is PATH_INFO 
null in this scenario? Tomcat's default servlet doesn't lose the
PATH_INFO, so why would a replacement? 

Later,
-- 
\ Craig Patrick McDaniel
/_\ Software Engineer
/_/_\ n + 1, Inc.
/_/_/_\ craigm@nplus1.net
/_/_/_/_\ (502) 479-5557

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


Re: Pretty URL's in Turbine?

Posted by Luke Holden <al...@prodigy.net>.
> In all 4 cases, you will need to write your own $link tool to generate the
> appropriate URLs, whereas if you use the abovementioned path prefix
> mapping, you can use the $link tool that comes with Turbine as is.

Well this is not always true. You can keep using the default $link tool. But 
of course you loose the simple url after you start navigating around the 
site. For me the main reason for the simplified url is to allow customers an 
easy to access 'bookmark' page. Or something that can be used in published 
material.

something like
http://site/support.jsp     

looks a lot better than 
http://site/servlet/templates/support.html

So in this situation I am not required to maintain the simple url... but use 
it for an easy access point. This might also be true for the original poster. 
In this case very little work has to be done to provide the simple url for 
the end user.

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


Re: Pretty URL's in Turbine?

Posted by Rodney Schneider <rl...@arcalink.com>.
On Wednesday 13 February 2002 04:15 am, you wrote:

> This document describes what can be done for modifying urls.
> Based on your email, it won't be enough for you, but it should
> make it clear that the part of the turbine urls that your
> client wants to hide is constrained by the servlet spec.
> <http://jakarta.apache.org/turbine/turbine-2/howto/url-rewriting-howto.html>

I recently discovered that you can use a path prefix mapping in your web.xml 
that will allow your URLs to be shorter then those mentioned in the URL 
Rewriting Howto.

Intead of:
http://www.foo.com/po/s/la/template/Foo.vm

You can easily achieve:
http://www.foo.com/po/la/template/Foo.vm

using the following servlet mapping in your web.xml:
    <servlet-mapping>
        <servlet-name>Turbine</servlet-name>
        <url-pattern>/la/*</url-pattern>
    </servlet-mapping>

If you make your webapp use the empty context path "" (in Tomcat you can do 
this by placing your webapp in ./webapps/ROOT, the URL is shortened even 
further to:
http://www.foo.com/la/template/Foo.vm

Other options to consider for making pretty URLs work with Turbine include:
1. Using a jsp:forward like Luke Holden mentioned in another post.
2. Using mod_rewrite like Eric Dobbs mentioned.
3. Hacking the Turbine servlet (Turbine.java) to make it work with a servlet
   extension mapping of *.vm.  You could check out the *.jsp and *.shtml
   servlets that come with Tomcat for ideas on how to implement this.  The
   main caveat is that PATH_INFO will always be null in this scenario.
4. You could write your own servlet to replace the default servlet for the
   webapp, using the default servlet mapping, /.  PATH_INFO will also be null
   in this scenario.  Your custom servlet could map pretty URLs to the ugly
   Turbine URLs by using a RequestDispatcher.forward().  Check out the
   servlet invoker that comes with Tomcat for ideas on how to implement this.

In all 4 cases, you will need to write your own $link tool to generate the
appropriate URLs, whereas if you use the abovementioned path prefix mapping, 
you can use the $link tool that comes with Turbine as is.

I hope this clears things up for everyone.  I am ultra busy at the moment, 
but when I get some free time, I will convert this email into an xdoc and 
submit it.

Regards,

-- Rodney

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


Re: Pretty URL's in Turbine?

Posted by Eric Dobbs <er...@dobbse.net>.
This document describes what can be done for modifying urls.
Based on your email, it won't be enough for you, but it should
make it clear that the part of the turbine urls that your
client wants to hide is constrained by the servlet spec.
<http://jakarta.apache.org/turbine/turbine-2/howto/url-rewriting-
howto.html>

mod_rewrite is the preferred option.


On Tuesday, February 12, 2002, at 10:05  AM, Craig McDaniel wrote:

> OK, this is really annoying, but I have a client who wants his URL's to
> look nice and friendly. I have ruled out using mod_rewrite in apache. I
> would like to be able to have
>
> http://server/news.html
>
> execute my News screen class in Turbine (i.e.,
> http://server/servlet/Turbine/template/news.html)
>
> Is there a clean way to do this?

not if you've ruled out mod_rewrite.


> I have been looking at Filters, but I
> am not sure if that will work in this case. I have also considered
> writing a servlet to forward the request (via RequestDispatcher) to
> Turbine. Are there any pitfalls to this method?

I don't know enough about filters to know if they can help you or not.

-Eric

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