struts2转发到不同页面

发布于 2024-09-12 04:11:20 字数 608 浏览 0 评论 0原文

我有 view.jsp 和 edit.jsp 页面。两者都调用操作的 load() 方法,该方法返回 SUCCESS。有没有办法转发到来自struts.xml 的页面请求,而不是这个?

<action name="call_1" method="load" class="package.action.List">
  <result name="success" type="json">/WEB-INF/view.jsp</result>
</action>
<action name="call_2" method="load" class="package.action.List">
  <result name="success" type="json">/WEB-INF/edit.jsp</result>
</action>

另外,我的操作将哈希图构建为 {"3":"adam","1":"brian","2":"brit","4":"den"},用于填充下拉菜单。它是根据值排序的,但由于某种原因 json 仍然按以下顺序显示它。 布莱恩->布里特->亚当->登。当键是字符串时,为什么仍然根据键排序。

I have view.jsp and edit.jsp pages. Both call load() method of an action, which returns SUCCESS. Is there a way to forward to the page request came from in struts.xml, instead of this?

<action name="call_1" method="load" class="package.action.List">
  <result name="success" type="json">/WEB-INF/view.jsp</result>
</action>
<action name="call_2" method="load" class="package.action.List">
  <result name="success" type="json">/WEB-INF/edit.jsp</result>
</action>

Also, my action builds hashmap as {"3":"adam","1":"brian","2":"brit","4":"den"}, which is used to populate a drop down menu. It is sorted based on values, but for some reason json still dispaly it in the following order.
brian->brit->adam->den. Why is still being sorted based on keys when keys are strings.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

俯瞰星空 2024-09-19 04:11:20

是的,您可以使用 通配符映射 来压缩您的两个 < code>定义合二为一。

<action name="list-*" method="load" class="package.action.List">
    <result name="success" type="json">/WEB-INF/{1}.jsp</result>
</action>

上面的代码将获取操作请求 URL 中连字符后面的部分,并使用它设置结果位置。然后,您可以使用这两个 URL 之一来调用它:

http://yourapp.com/list-view.action
http://yourapp.com/list-edit.action

至于对 JSON 对象进行排序,您可以阅读 此答案,了解有关如何创建比较器并按照您想要的顺序获取它的更多详细信息。

Yes, you can use wildcard mappings to condense your two <action> definitions into one.

<action name="list-*" method="load" class="package.action.List">
    <result name="success" type="json">/WEB-INF/{1}.jsp</result>
</action>

The above will take the part after the hyphen in the action request URL and use it set the result location. You could then call it with either of these two URLs:

http://yourapp.com/list-view.action
http://yourapp.com/list-edit.action

As for sorting your JSON object, you can read this answer for more details on how to create a comparator and get it in the order you want.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文