分析Hibernate设置过滤器

开发 后端
这里介绍Hibernate设置过滤器映射,因为过滤器不能过滤全部的程序,所以可以用列表的形式来增加需要过滤的文件。

Hibernate还是比较常用的,于是我研究了一下Hibernate设置过滤器,在这里拿出来和大家分享一下,希望对大家有用。

通过Hibernate设置过滤器判断用户权限.

第一步:建立UserPermissionFilter类.

import javax.servlet.*;  
import javax.servlet.http.*;  
import java.io.*;  
import java.util.*;  
 
import test.system.SysUserApi;  
import test.vo.SysUserVO;  
import test.system.dao.SysUserDao;  
import test.Const;  
 
public class UserPermissionFilter extends HttpServlet implements Filter {  
 
protected FilterConfig filterConfig = null;  
 
public void destroy() {  
this.filterConfig = null;  
}  
 
public void doFilter(ServletRequest request,ServletResponse response,
FilterChain filterChain) throws IOException,ServletException {  
try {   HttpServletRequest req = (HttpServletRequest) request;   SysUserVO userSession = new SysUserVO();   userSession = (SysUserVO)req.getSession().getAttribute(Const.SESSION_USER);   if (userSession == null) {   HttpServletResponse rep = (HttpServletResponse) response;     rep.sendRedirect("/admin/login.jsp");   }   else{   filterChain.doFilter(request, response);   }   }   catch (Exception e) {}   }   public void init(FilterConfig filterConfig) throws ServletException {   this.filterConfig = filterConfig;   }   public FilterConfig getFilterConfig() {   return filterConfig;   }     public void setFilterConfig(FilterConfig filterConfig) {   this.filterConfig = filterConfig;   }    
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.

第二步:配置WEB.xml文件,Hibernate设置过滤器:

<filter> 
<filter-name>userpermission</filter-name> 
<filter-class>sports.tools.UserPermissionFilter</filter-class> 
</filter> 
  • 1.
  • 2.
  • 3.
  • 4.

Hibernate设置过滤器映射,因为过滤器不能过滤全部的程序,所以可以用列表的形式来增加需要过滤的文件.如下.一个过滤器可以过滤多个映射文件.

<filter-mapping> 
<filter-name>userpermission</filter-name> 
<url-pattern>/admin/index.jsp</url-pattern> 
</filter-mapping> 
 
<filter-mapping> 
<filter-name>userpermission</filter-name> 
<url-pattern>/admin/edit/*</url-pattern> 
</filter-mapping> 
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.

【编辑推荐】

  1. Spring Hibernate简单讨论
  2. OSGi与Spring:设置Spring DM开发环境
  3. 使用Spring DM创建Hello World,以及OSGi服务
  4. Spring MVC总结:善用注解,生活更轻松
  5. 概括spring hibernate集成
责任编辑:佚名 来源: Yesky
相关推荐

2009-06-18 10:13:00

Hibernate过滤

2009-09-25 15:19:44

Hibernate过滤

2021-07-05 15:22:03

Servlet过滤器客户端

2024-01-05 09:04:35

隆过滤器数据结构哈希函数

2024-11-04 08:45:48

布隆过滤器元数据指纹值

2009-07-08 15:30:56

Servlet过滤器

2011-06-29 16:14:59

Qt 事件 过滤器

2009-07-08 16:07:04

Servlet过滤器配

2009-07-14 09:09:08

Swing模型过滤器

2017-05-04 22:30:17

Zuul过滤器微服务

2009-07-08 17:33:37

Servlet过滤器

2017-07-18 14:10:31

大数据Apache Flum过滤器

2024-03-15 11:21:22

布隆过滤器数据库数据

2009-07-06 13:02:49

Servlet过滤器

2016-12-09 15:04:54

网络数据流量

2016-12-07 09:56:13

JavaFilter过滤器

2023-01-26 01:41:27

核心全局过滤器

2017-04-12 14:43:01

Spring ClouZuul过滤器

2010-03-01 14:45:07

Linux文件重定向

2009-07-03 18:26:11

Servlet过滤器
点赞
收藏

51CTO技术栈公众号