views:

25

answers:

2

I'm using Struts 1. I have a list of stores in our database. The store table contains store id, store name, url friendly store path, store address. For example, "1; Store 1; the-wonderful-store; 52 Main St.",

When a request comes in for /store/the-wonderful-store.do, I want to grab "the-wonderful-store" and query the DB for the store for this path. Now render the page with this query result.

The page uses tiles for its template.

How can I do this with Struts 1?

And if not, since I front this with Apache2, is it safe to just

RewriteEngine On
RewriteRule /store/(.*) /store.do?path=$1 [NC,PT]
+2  A: 

Use URLRewrite filter. It will allows the users to send in requests like /store/the-wonderful-store and the rewrite filter can forward this to your action passing in needed data from the url to your action like showStore.do?name=the-wonderful-store

In this way you will have all the logic for displaying stores in one Action and URLRewrite Filter will forward the matching requests as you want.

Check out their documentation for more information.

Faisal Feroz
+1 URLRewrite Filter is sort of the mod_rewrite for java world. You can use mod_rewrite for apache as well.
Tingu
A: 

You can use wildcards in your mapping. And from there you can check the requested URL to get your information.


Resources :

Colin Hebert