我有很多目的地(比如 150 多个),每个目的地都有 2 种不同的变体:
- 一个
- B
我已经为每个变体生成了一个 html。例如:
- NewYork-A.html
- NewYork-B.html
- 旧金山-A.html
- 旧金山-B.html
- 拉斯维加斯-A.html
- 拉斯维加斯-B.html ...
通用格式为:
- 目的地-A.html
- 目的地-B.html
每个文件都写入/seo/Destination/
如何将给定 URL 映射到 struts 2 中的这些文件:
www.mysite.com/NewYork-Tourism
=> www.mysite.com/seo/Destinations/NewYork-A.html 和
www.mysite.com/NewYork-Travel
=> www.mysite.com/seo/Destinations/NewYork-B.html
通用:
www.mysite.com/Destination-Tourism
=> www.mysite.com/seo/Destinations/Destination-A.html
并且
www.mysite.com/Destination-Travel
=> www.mysite.com/seo/Destinations/Destination-B.html
我能想到的一种方法是生成与 (destination *variant_types) 一样多的操作,然后将每个操作的结果映射到正确的 html 文件。像这样的事情:
<action name="NewYork-Tourism">
<result name="success">/seo//Destination/NewYork-A.html</result>
</action>
<action name="NewYork-Travel">
<result name="success">/seo//Destination/NewYork-B.html</result>
</action>
..等等
还有其他(更好)的方法吗?
最佳答案
在我看来,一种快速的方法是使用通配符映射,Struts2有一种方法,即通配符,它似乎更适合你。
As an application grows in size, so will the number of action mappings. Wildcards can be used to combine similar mappings into one more generic mapping.
类似的东西
<action name="List*s" class="actions.List{1}s">
<result>list{1}s.jsp</result>
</action>
更多详情请参阅文档
关于java - 我如何使用struts 2将url重定向到特定页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12085921/