• 大小: 10KB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2021-06-23
  • 语言: 其他
  • 标签: Filter  

资源简介

Filter使用范例--登陆验证,具体效果和过程看博文 http://blog.csdn.net/evankaka/article/details/45480101

资源截图

代码片段和文件信息

package com.mucfc;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
/** 
 *  
 * 权限过滤器 
 *  
 * */    
public class AuthorityFilter implements Filter {
 private FilterConfig config;  
@Override
public void destroy() {
 this.config=null;  
}

@Override
public void doFilter(ServletRequest request ServletResponse response
FilterChain chain) throws IOException ServletException {
//获取Filter配置参数  
        String encoding=config.getInitParameter(“encoding“);  
        String loginPage=config.getInitParameter(“loginPage“);  
        String afterLogin=config.getInitParameter(“afterLogin“);  
        //设置request编码  
        request.setCharacterEncoding(encoding);  
        HttpServletRequest requ=(HttpServletRequest) request;  
        HttpSession session=requ.getSession();  
        //获取客户请求页面  
        String requestPath=requ.getServletPath();   
        String name=requ.getParameter(“username“);
         if(name==““||name==null){  
            System.out.println(“权限拦截器的消息:“+“终止“);  
         HttpServletResponse resq=(HttpServletResponse)response;
            resq.sendRedirect(requ.getContextPath()+loginPage);
        }else{  
            System.out.println(“权限拦截器的消息:“+“放行“);  
            request.setCharacterEncoding(“UTF-8“);
            chain.doFilter(request response);  
        }  
}

@Override
public void init(FilterConfig config) throws ServletException {
this.config=config; 
}   

}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2015-05-04 16:33  ServletLearningChapter2_2\
     文件         841  2015-05-04 16:33  ServletLearningChapter2_2\.classpath
     文件        1058  2015-05-04 16:33  ServletLearningChapter2_2\.project
     目录           0  2015-05-04 16:41  ServletLearningChapter2_2\.settings\
     文件         503  2015-05-04 16:33  ServletLearningChapter2_2\.settings\.jsdtscope
     文件         106  2015-05-04 16:44  ServletLearningChapter2_2\.settings\org.eclipse.core.resources.prefs
     文件         364  2015-05-04 16:33  ServletLearningChapter2_2\.settings\org.eclipse.jdt.core.prefs
     文件         527  2015-05-04 16:33  ServletLearningChapter2_2\.settings\org.eclipse.wst.common.component
     文件         345  2015-05-04 16:33  ServletLearningChapter2_2\.settings\org.eclipse.wst.common.project.facet.core.xml
     文件          49  2015-05-04 16:33  ServletLearningChapter2_2\.settings\org.eclipse.wst.jsdt.ui.superType.container
     文件           6  2015-05-04 16:33  ServletLearningChapter2_2\.settings\org.eclipse.wst.jsdt.ui.superType.name
     目录           0  2015-05-04 16:33  ServletLearningChapter2_2\build\
     目录           0  2015-05-17 13:48  ServletLearningChapter2_2\build\classes\
     目录           0  2015-05-17 13:48  ServletLearningChapter2_2\build\classes\com\
     目录           0  2015-05-17 13:48  ServletLearningChapter2_2\build\classes\com\mucfc\
     文件        2663  2015-05-17 13:48  ServletLearningChapter2_2\build\classes\com\mucfc\AuthorityFilter.class
     目录           0  2015-05-04 16:33  ServletLearningChapter2_2\src\
     目录           0  2015-05-04 16:33  ServletLearningChapter2_2\src\com\
     目录           0  2015-05-04 16:34  ServletLearningChapter2_2\src\com\mucfc\
     文件        1897  2015-05-04 18:35  ServletLearningChapter2_2\src\com\mucfc\AuthorityFilter.java
     目录           0  2015-05-04 16:41  ServletLearningChapter2_2\WebContent\
     文件         567  2015-05-04 18:31  ServletLearningChapter2_2\WebContent\Login.jsp
     文件         519  2015-05-04 17:32  ServletLearningChapter2_2\WebContent\Main.jsp
     目录           0  2015-05-04 16:33  ServletLearningChapter2_2\WebContent\meta-INF\
     文件          39  2015-05-04 16:33  ServletLearningChapter2_2\WebContent\meta-INF\MANIFEST.MF
     目录           0  2015-05-04 16:40  ServletLearningChapter2_2\WebContent\WEB-INF\
     目录           0  2015-05-04 16:33  ServletLearningChapter2_2\WebContent\WEB-INF\lib\
     文件        1086  2015-05-04 18:42  ServletLearningChapter2_2\WebContent\WEB-INF\web.xml

评论

共有 条评论