struts2配置全局的结果集和包之间的继承

来源:互联网 发布:网络被动攻击 编辑:程序博客网 时间:2024/06/07 19:13

  struts2总结:

    拦截器:

    创建自己的拦截器:实现接口   Interceptor 重写内部方法 

    @Override

public String intercept(ActionInvocation invok) throws Exception {

        Map<String, Object> session= ActionContext.getContext().getSession();

  if(session.get("loginAdnin")!=null){

  return invok.invokeActionOnly();//跳到下一个action,invokeAction跳到下一个拦截器

   

  }

return ActionSupport.LOGIN;

}

    工作原理:拦截器 123,321

    struts.xml配置

    1、首先声明拦截器:

      <!--声明拦截器  -->

<interceptors>

<interceptor name="login" class="com.lanou.mp.controller.interceptor.LoginInteceptor"></interceptor>

<interceptor-stack name="loginvalid">

<interceptor-ref name="defaultStack"></interceptor-ref>

  <interceptor-ref name="login"></interceptor-ref>

</interceptor-stack>

</interceptors>

2、再在拦截的action初使用

<!-- 应用拦截器 -->

<interceptor-ref name="loginvalid"></interceptor-ref>

xml中配置全局的结果集

  <package>

<!-- 配置全局 -->

<global-results>

<result name="login" type="redirect">

/index.html

</result>

<result name="error" type="redirect">

/pages/error.html

</result>

</global-results>

</package>

在struts2中是包(package)的继承

可以配置全局的包让其他包继承

<!--redirectAction跳到同包下的action  ,redirect可以跳到不同包下的action-->

原创粉丝点击