自搭建项目笔记Spring+Struts2+Hibernate《二》

缓存数据
 
文件上下传
 
权限控制(spring security)
 
自定义拦截器(Interceptor)
 
表单验证
 
 
 
导出EXCEL
 
读取XML文档(熟悉SAX、DOM以及JDOM的优缺点 )
 
 
 
 
 
 
 
 
 
 
 
 
 
一、 缓存数据
      在Spring容器加载后自动缓存数据库数据
 

在web.xml里配置一个listener

       <listener>     

<listener-class>com.cib.yypt.utils.CacheGenetaror</listener-class>

       </listener>

该listener implements ServletContextListener

然后在这个listener的contextInitialized方法里操作要执行的事情

遇到问题1、eclipse中the import javax.servlet cannot be resolved问题
 因为缺少servlet-api.jar包
解决:在pom.xml文件加入:
<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>javax.servlet-api</artifactId>
    <version>3.1.0</version>
</dependency>
 
 
二、文件上下传
 
 
 
 
 
 
 
 
 
 
 
三 自定义拦截器
 
1、在创建拦截器时,两种方法,继承父类:AbstractInterceptor,实现接口:Interceptor。
2、写个类CheckLoginInterceptor implements Interceptor
3、在strust.xml 配置:
 
<package name="test" namespace="/" extends="struts-default">

<interceptors>
    <interceptor name="authority" class="test.t1.user.util.CheckLoginInterceptor"></interceptor>
    <!-- 定义一个拦截栈 -->
    <interceptor-stack name="myDefaultStack">
        <interceptor-ref name="defaultStack"></interceptor-ref><!-- 默认拦截栈 -->
        <interceptor-ref name="authority"></interceptor-ref><!-- 自定义拦截栈 -->
    </interceptor-stack>
</interceptors>
<global-results>
    <result name="login">/jsp/message.jsp</result>
</global-results>

</package>
4、在需要拦截的action上配置注解:
 
(注意:action的父包里要有该拦截器配置)
 
 
 
 
 
四、权限控制(spring security)
 
 
 
 
 
 
 
 
 
 
 
http://blog.csdn.net/chenleixing/article/details/44353491
 
 
 


 
原文地址:https://www.cnblogs.com/qingchun-com/p/6298363.html