設置攔截還能打進來,struts2基礎----自定義攔截器

 2023-10-07 阅读 23 评论 0

摘要:  這一章,我們開始struts2中攔截器的學習。 自定義攔截器 一、增加一個自定義的攔截器為類 package com.huhx.interceptor;import com.opensymphony.xwork2.ActionInvocation; import com.opensymphony.xwork2.interceptor.AbstractInterceptor;public class Registe

  這一章,我們開始struts2中攔截器的學習。

自定義攔截器

一、增加一個自定義的攔截器為類

package com.huhx.interceptor;import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;public class RegisterInterceptor extends AbstractInterceptor {private static final long serialVersionUID = 1L;@Overridepublic String intercept(ActionInvocation invocation) throws Exception {System.out.println("攔截器開始運行....");String resultString = invocation.invoke();System.out.println("攔截器結束運行....");return resultString;}
}

?二、修改struts.xml配置文件,內容如下:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN""http://struts.apache.org/dtds/struts-2.0.dtd">
<struts><package name="default" namespace="/" extends="struts-default"><interceptors><interceptor name="registerInterceptor" class="com.huhx.interceptor.RegisterInterceptor"></interceptor></interceptors><action name="hello" class="com.huhx.struts.HuhxAction"><result name="success">/huhx.jsp</result><interceptor-ref name="defaultStack"></interceptor-ref><interceptor-ref name="registerInterceptor"></interceptor-ref></action></package>
</struts>

?三、訪問地址:http://localhost:8080/StrutsTest1/hello.action,后臺打印地址:

攔截器開始運行....
hello world.
攔截器結束運行....

設置攔截還能打進來,?

?友情鏈接

?

轉載于:https://www.cnblogs.com/huhx/p/baseStruts2.html

版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。

原文链接:https://hbdhgg.com/3/125853.html

发表评论:

本站为非赢利网站,部分文章来源或改编自互联网及其他公众平台,主要目的在于分享信息,版权归原作者所有,内容仅供读者参考,如有侵权请联系我们删除!

Copyright © 2022 匯編語言學習筆記 Inc. 保留所有权利。

底部版权信息