java - 我如何使用struts 2将url重定向到特定页面

标签 java jsp redirect struts2

我有很多目的地(比如 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.htmlwww.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/

相关文章:

php - 错误的重定向 CakePHP

python - 使用 Linux 重定向从 Python 脚本覆盖文件

Java 事件传播停止

java - 在谷歌应用程序上创建员工考勤应用程序

java - JSP 应用程序登录

java - 从 JavaScript 调用 Servlet

java - 在 JSP 中解析 CSV 文件

c# - 如何根据输入在同一方法中返回 JsonResult 或 ActionResult?

Java:创建一个程序来查找圆柱体的表面积和体积

java - 使用广度优先搜索算法存储迷宫求解路径