package fiters;
import javax.servlet.Filter;
import javax.servlet.*;
import java.io.IOException;
import javax.servlet.http.*;

public class ogFiters implements Filter{

 public void init(FilterConfig parm1) throws ServletException {
  // TODO: Add your code here
 }


 public void doFilter(ServletRequest request, ServletResponse response,
    FilterChain chain) throws IOException, ServletException
 {
  HttpServletRequest hsRequest = (HttpServletRequest)request;
  HttpServletResponse hsResponse = (HttpServletResponse)response;
  request.setCharacterEncoding("gb2312");
  response.setCharacterEncoding("gb2312");
 
  /*HttpSession session = hsRequest.getSession();
 
  //没登录
  if(session.getAttribute("userName")==null)
  {
  
   String uri = hsRequest.getRequestURI();
   //请求登录页面
   if(uri.endsWith("login.html")|| uri.endsWith("login"))
   {
    chain.doFilter(request,response);
   }
   //请求其它页面
   else
   {
    hsResponse.sendRedirect("login.html");
   }
  
  }
  //登录成功
  else
  {
   chain.doFilter(request,response);
  }*/
  chain.doFilter(request,response);
 
 
 
 }

 
 public void destroy() {
  // TODO: Add your code here
 }

}
web.xml配置
<web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.4" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee   http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
     <filter>
  <filter-name>loginfilter</filter-name>
  <filter-class>fiters.ogFiters</filter-class>
 </filter>
 <filter-mapping>
  <filter-name>loginfilter</filter-name>
  <url-pattern>*.do</url-pattern>
 </filter-mapping>

 

posted on 2011-06-29 15:46 sanmao 阅读(2977) 评论(0)  编辑  收藏

只有注册用户登录后才能发表评论。


网站导航:
 

常用链接

留言簿(5)

随笔分类

随笔档案

搜索

  •  

最新评论

阅读排行榜

评论排行榜