二级Java:保存登录用户信息-userInfo
来源:优易学  2011-8-21 18:14:43   【优易学:中国教育考试门户网】   资料下载   IT书店

 

  然后在系统的过滤器中配置下:
  package com.jframe.http;
  import java.io.IOException;
  import javax.servlet.*;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  import com.ygsoft.basic.dao.HibernateDaoSupport;
  import com.ygsoft.util.LocalThreadBean;
  public class EncodingFilter
  implements Filter
  {
  private FilterConfig config;
  private String targetEncoding;
  private LocalThreadBean localThreadBean;
  public EncodingFilter()
  {
  config = null;
  targetEncoding = "GB18030";
  localThreadBean =new LocalThreadBean();
  }
  public void init(FilterConfig config)
  throws ServletException
  {
  this.config = config;
  try
  {
  String temp = config.getInitParameter("encoding");
  if(temp != null)
  targetEncoding = temp;
  }
  catch(Exception exception) { }
  }
  public void destroy()
  {
  config = null;
  targetEncoding = null;
  }
  public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
  throws IOException, ServletException
  {
  HttpServletRequest hreq = (HttpServletRequest)request;
  HttpServletResponse hres = (HttpServletResponse)response;
  request.setCharacterEncoding(targetEncoding);
  chain.doFilter(request, response);
  LocalThreadBean.setContext((HttpServletRequest)request);
  // 关闭遗漏的 Session
  HibernateDaoSupport.closeSessionList();
  }
  }
  当然,还需要在web.xml中加上此过滤bean了。

上一页  [1] [2] 

责任编辑:小草

文章搜索:
 相关文章
热点资讯
资讯快报
热门课程培训