日期:2014-05-17 浏览次数:20718 次
public class GetCUIListen implements Filter{ private HttpServletRequest httpServletRequest; @Override public void destroy() { // TODO Auto-generated method stub } @Override public void doFilter(ServletRequest arg0, ServletResponse arg1, FilterChain arg2) throws IOException, ServletException { // TODO Auto-generated method stub httpServletRequest=(HttpServletRequest)arg0; User user; if(httpServletRequest.getSession().getAttribute("currentUser")==null&&(user=getUser())!=null) httpServletRequest.getSession().setAttribute("currentUser",user ); System.out.println("doFilter"); arg2.doFilter(arg0, arg1); } private User getUser() { // TODO Auto-generated method stub // System.out.println(hibernateTemplate==null); //我本来想spring注入进来的,可是不对 // session.beginTransaction(); // User user=(User) session.load(User.class, "wubuqilai@gmail.com"); // session.getTransaction().commit(); // session.close(); // return user; return null; } @Override public void init(FilterConfig arg0) throws ServletException { // TODO Auto-generated method stub System.out.println("init"); } }