gpt4 book ai didi

java - Struts2 如何将 URL 映射到操作?

转载 作者:行者123 更新时间:2023-11-30 07:54:25 27 4
gpt4 key购买 nike

我想了解我很久以前使用过的东西,但不知道它是如何工作的。

当我点击这样的超链接时:

<a href="name_action.action">Link</a>

Struts2如何激活映射到struts.xml文件中的 Action ?

<action name="name_action">
<result type="redirect">web/page.jsp</result>
</action>

最佳答案

Struts2 将 URL 映射到带有 ActionMapper 的操作.

The ActionMapper interface provides a mapping between HTTP requests and action invocation requests and vice-versa.

When given an HttpServletRequest, the ActionMapper may return null if no action invocation request matches, or it may return an ActionMapping that describes an action invocation for the framework to try.

The ActionMapper is not required to guarantee that the ActionMapping returned be a real action or otherwise ensure a valid request. Accordingly, most ActionMappers do not need to consult the Struts configuration just to determine if a request should be mapped.

Just as requests can be mapped from HTTP to an action invocation, the opposite is true as well. However, because HTTP requests (when shown in HTTP responses) must be in String form, a String is returned rather than an actual request object.

<小时/>

By default, the DefaultActionMapper is used:

Default action mapper implementation, using the standard *.[ext] (where ext usually "action") pattern. The extension is looked up from the Struts configuration key struts.action.extension.

注意:您不应该直接登陆 JSP,而应该在通过操作后调度它们。

关于java - Struts2 如何将 URL 映射到操作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32869122/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com