首页 > 其他 > 详细

Struts学习心得1

时间:2014-02-07 04:16:08      阅读:348      评论:0      收藏:0      [点我收藏+]

1。struts2是原形的。Servlet是单例的

2。拦截器

1。自定义拦截器的话 首先要继承AbstractInterceptor接口 重写Interceptor方法


public class MyInterceptor extends AbstractInterceptor {


@Override

public String intercept(ActionInvocation arg0) throws Exception {

// TODO Auto-generated method stub

long one =System.currentTimeMillis();

String result=arg0.invoke();//调用Action

long two=System.currentTimeMillis();

System.out.println(".."+(two-one));

return result;

}

}

2.配置拦截器

<interceptors>

<interceptor name="myinterceptor" class="com.Interceptor.MyInterceptor"></interceptor>

</interceptors>

3.应用拦截器


<action name="inter" class="com.act.InterceptorAction" method="testInter">

<result>index.jsp</result>

<interceptor-ref name="myinterceptor"/>

<interceptor-ref name="defaultStack"/>

</action>

此外Struts还提供了20多个拦截器供调用

Struts学习心得1

原文:http://sw3458856.blog.51cto.com/6499064/1356248

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!