Struts 配置文件中如何重定向Url
在 Struts 配置文件中,可以使用 <result> 元素来重定向 Url。具体步骤如下:
- 在
struts.xml中定义一个 Action:
<action name="redirect" class="com.example.RedirectAction">
<result name="success" type="redirect">/new-url.jsp</result>
</action>
- 在
RedirectAction中返回SUCCESS:
public class RedirectAction extends ActionSupport {
public String execute() {
return SUCCESS;
}
}
- 在
<result>元素中设置type属性为redirect,并指定重定向的 Url。
这样,在访问 /redirect.action 时,就会重定向到 /new-url.jsp
原文地址: https://www.cveoy.top/t/topic/crq3 著作权归作者所有。请勿转载和采集!