You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Manri Offermann <ta...@eastbeam.co.jp> on 2005/01/05 06:25:55 UTC

Friendly URL and Parameter in URL

Hi,

anybody have some ideas how to accomplish this:

http://foo.com/bar/12345/detail.html  equivalent with 
(http://foo.com/bar/detail.html?id=12345)

I would like to include a parameter into the URL to get better indexing by 
crawlers/search engines. The parameter holds an identifier of a row in a 
database.


Do I need a Filter which does a sort of a "rewrite"?
Or should I write a custom Service?

Any pointers please,


Manri





---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


Re: Friendly URL and Parameter in URL

Posted by Erik Hatcher <er...@ehatchersolutions.com>.
On Jan 5, 2005, at 12:25 AM, Manri Offermann wrote:
> anybody have some ideas how to accomplish this:
>
> http://foo.com/bar/12345/detail.html  equivalent with 
> (http://foo.com/bar/detail.html?id=12345)

I dislike that second URL example.... the .html extension indicates 
something static, and passing parameters to it seems odd.  The first 
example is nice.

> I would like to include a parameter into the URL to get better 
> indexing by crawlers/search engines. The parameter holds an identifier 
> of a row in a database.
>
>
> Do I need a Filter which does a sort of a "rewrite"?
> Or should I write a custom Service?

Until the mighty Tapestry 3.1 promises come true, I recommend using a 
servlet filter for this.  I'm using a simple filter in front of 
lucenebook.com so URL's look like this:

	http://www.lucenebook.com/search?query=tapestry+OR+else

In this case, I wanted the query parameter, but I didn't want the 
?service=external/Search&sp=.... stuff.  The filter I'm using is pasted 
below.  My page implements the IExternalPage interface, and I treat it 
like a servlet and pull the query parameter off the request like this:

   public void activateExternalPage(Object[] parameters, IRequestCycle 
cycle) {
     HttpServletRequest request = cycle.getRequestContext().getRequest();
     setProperty("query", request.getParameter("query"));

     search(cycle);
   }

You should be able to extrapolate from this code to accomplish what you 
want.

	Erik



public class SearchFilter implements Filter {
   public void init(FilterConfig config) throws ServletException {
   }

   public void doFilter(ServletRequest servletRequest, ServletResponse 
servletResponse, FilterChain chain) throws IOException, 
ServletException {
     RequestDispatcher rd = servletRequest.getRequestDispatcher("/app");

     rd.forward(new RequestWrapper((HttpServletRequest)servletRequest), 
servletResponse);
   }

   public void destroy() {
   }

   private static class RequestWrapper extends HttpServletRequestWrapper 
{
     private Hashtable parameterMap;

     public RequestWrapper(HttpServletRequest request) {
       super(request);

       parameterMap = new Hashtable(request.getParameterMap());
       parameterMap.put("service", new String[] {"external/Search"});
     }

     public String getParameter(String name) {
       String[] params = (String[]) parameterMap.get(name);
       return (params == null || params.length == 0) ? null : params[0];
     }

     public Map getParameterMap() {
       return Collections.unmodifiableMap(parameterMap);
     }

     public Enumeration getParameterNames() {
       return parameterMap.keys();
     }

     public String[] getParameterValues(String name) {
       return (String[]) parameterMap.get(name);
     }
   }
}


---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


Re: Friendly URL and Parameter in URL

Posted by Erik Hatcher <er...@ehatchersolutions.com>.
On Jan 5, 2005, at 11:28 AM, Jamie Orchard-Hays wrote:

> I did this on a storefront a year or two ago using URL rewriting. If 
> you're on apache, then you can use mod_url_rewrite, if you're on IIS 
> like I was, you can purchase one of several tools to do this.
>
> Another way, which I haven't used, but I think Erik and Howard have, 
> is to use filter servlets to do your rewriting.

While mod_rewrite and the servlet filter approach are nice, its only 
half of the solution though.  The other half is creating the links in 
the first place.  A custom link component could do this cleanly, and 
you'd just use it instead of the built-in link components.

In my case, I simply use <form> (in a SiteMesh border.jsp):

       <form name="searchform" action="/search" method="GET">
         Search inside Lucene in Action: <input class="inputField" 
type="text" size="30" name="query" value="<%=query%>"/>
         <input type="submit" value="search"/>
       </form>

Erik


---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


Re: Friendly URL and Parameter in URL

Posted by Jamie Orchard-Hays <ja...@dang.com>.
I did this on a storefront a year or two ago using URL rewriting. If you're 
on apache, then you can use mod_url_rewrite, if you're on IIS like I was, 
you can purchase one of several tools to do this.

Another way, which I haven't used, but I think Erik and Howard have, is to 
use filter servlets to do your rewriting.

Jamie

----- Original Message ----- 
From: "Manri Offermann" <ta...@eastbeam.co.jp>
To: "Tapestry users" <ta...@jakarta.apache.org>
Sent: Wednesday, January 05, 2005 12:25 AM
Subject: Friendly URL and Parameter in URL


> Hi,
>
> anybody have some ideas how to accomplish this:
>
> http://foo.com/bar/12345/detail.html  equivalent with 
> (http://foo.com/bar/detail.html?id=12345)
>
> I would like to include a parameter into the URL to get better indexing by 
> crawlers/search engines. The parameter holds an identifier of a row in a 
> database.
>
>
> Do I need a Filter which does a sort of a "rewrite"?
> Or should I write a custom Service?
>
> Any pointers please,
>
>
> Manri
>
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org