关闭

struts1的拦截器2

1135人阅读 评论(0) 收藏 举报
1·首先写一个类 MyInterceptor 继承ActionServlet,代码如下
public class MyInterceptor extends ActionServlet {

	@Override
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws IOException, ServletException {
		// TODO Auto-generated method stub
		System.out.println("dopost");//这里可以写成自己的拦截代码。。大家就随意发挥吧
		super.doPost(request, response);
	}
	@Override
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws IOException, ServletException {
		// TODO Auto-generated method stub
		System.out.println("doget");//这里可以写成自己的拦截代码。。大家就随意发挥吧
		super.doGet(request, response);
	}
}



2·然后把WEB.xml改下下面这样
  <servlet>
    <servlet-name>action</servlet-name>
    <servlet-class>org.apache.struts.action.MyInterceptor.MyInterceptor</servlet-class>
    <init-param>
      <param-name>config</param-name>
      <param-value>/WEB-INF/struts-config.xml</param-value>
    </init-param>
    <init-param>
      <param-name>debug</param-name>
      <param-value>3</param-value>
    </init-param>
    <init-param>
      <param-name>detail</param-name>
      <param-value>3</param-value>
    </init-param>
    <load-on-startup>0</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>action</servlet-name>
    <url-pattern>*.do</url-pattern>
  </servlet-mapping>



哈哈。。一个简单的拦截
0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:634148次
    • 积分:8837
    • 等级:
    • 排名:第2215名
    • 原创:327篇
    • 转载:40篇
    • 译文:0篇
    • 评论:25条
    最新评论