创建struts2项目的步骤和拦截器配置
2017-04-13 09:58
375 查看
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>
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>
相关文章推荐
- 电商项目笔记之一:复杂一些的struts2配置(自定义拦截器)
- 使用IDEA创建javaweb项目并配置详细步骤+导出war包详细步骤
- WEB应用环境的搭建(二)Eclipse配置Tomcat步骤及创建web项目
- Eclipse 配置Struts2,创建一个空项目,报错There is no action ....
- eclipse 中创建 整合springmvc+mybatis+maven 的java web项目步骤,以及maven仓库配置
- Struts2使用12 -- 拦截器2 -- 配置
- Struts2使用20 -- 注解配置2 -- 生命周期回调注解(拦截器注解)
- 在Eclipse中配置Struts2项目
- 关于如何在BizTalk中为项目创建单独的配置文件[翻译]
- 在Eclipse中配置Struts2项目(五)
- windows server 2003 下项目配置步骤
- Struts2的标签及其自定义token拦截器的定义及配置
- 在Eclipse中配置Struts2项目(四)
- 创建拦截器配置
- struts2的拦截器配置详解
- 使用Maven管理项目-----创建 Struts2,Spring,Hibernate项目
- 传智播客--struts2.x的常量配置,动态方法调用,通配符,拦截器,ValueStack和标签
- VC7配置编译环境创建驱动项目
- 在Eclipse中配置Struts2项目(三)
- Struts2配置文件、拦截器详解