使用 Struts 1 的动态 URL
我正在使用 Struts 1。我的数据库中有一个商店列表。商店表包含商店 ID、商店名称、URL 友好商店路径、商店地址。例如,“1; Store 1; the-wonderful-store; 52 Main St.”,
当请求 /store/the-wonderful-store.do 时,我想抓取“the-wonderful-store”并且在数据库中查询该路径的商店。现在使用此查询结果渲染页面。
该页面使用图块作为其模板。
我如何使用 Struts 1 做到这一点?
如果没有,因为我用 Apache2 来解决这个问题,那么安全吗?
RewriteEngine On
RewriteRule /store/(.*) /store.do?path=$1 [NC,PT]
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]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用URLRewrite 过滤器。它将允许用户发送类似 /store/the-wonderful-store 的请求,并且重写过滤器可以将其转发到您的操作,将所需的数据从 url 传递到您的操作,如
showStore.do?name=the- beautiful-store
通过这种方式,您将在一个 Action 中拥有显示商店的所有逻辑,并且 URLRewrite Filter 将根据您的需要转发匹配的请求。
请查看他们的文档了解详情。
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.
您可以在映射中使用通配符。从那里您可以检查请求的 URL 以获取您的信息。
资源:
You can use wildcards in your mapping. And from there you can check the requested URL to get your information.
Resources :