创建struts2项目的步骤和拦截器配置

来源:互联网 发布:access录入数据 编辑:程序博客网 时间:2024/06/15 21:48
1,创建web project
2,右键加载struts2的框架
3,写页面,写对应的action
4,写配置文件。加上package,action
5,编写action里面对应的后台action和实体类
6,将后台处理成功之后的页面加在result标签里面
7,写一个result页面。
8,将工程加载到tomcat里面
9,启动tomcat,访问。

如何加载拦截器
1,写一个拦截器的包
2,写一个拦截器类。
有三种方式: *第一种:实现interceptor接口
          *第二种:继承abstractInterceptor类
             *第三种:继承MethodFilterInterceptor类
3,在配置文件里面定义拦截器
<!-- 定义一个拦截器 -->
        <interceptors>
            <interceptor name="userInterceptor" class="com.hope.web.interceptor.UserInterceptor"></interceptor>
            <!-- 定义一个拦截器栈 -->
            <interceptor-stack name="userStack">
                <interceptor-ref name="userInterceptor"></interceptor-ref>
                <interceptor-ref name="defaultStack"></interceptor-ref>
            </interceptor-stack>
        </interceptors>
4,在配置文件里面使用拦截器
<action name="login" class="com.hope.web.action.LoginAction" method="login">
            <result name="success">result.jsp</result>
            <!-- 如何使用一个拦截器 -->
            <interceptor-ref name="userInterceptor"></interceptor-ref>
            <!-- 使用拦截器栈 -->
            <interceptor-ref name="userStack"></interceptor-ref>
        </action>

0 0
原创粉丝点击