struts1的拦截器,一个简单的示范
1·首先写一个类 MyInterceptor 继承ActionServlet,代码如下
2·然后把WEB.xml改下下面这样
- 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>
版权声明:本文为博主原创文章,未经博主允许不得转载。