Java教程

狂神说java超市管理系统filten

本文主要是介绍狂神说java超市管理系统filten,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

转码

package filter;


import javax.servlet.*;
import java.io.IOException;

public class FenCo implements Filter {


    public void init(FilterConfig filterConfig) throws ServletException {

    }

    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        servletRequest.setCharacterEncoding("utf8");
        servletResponse.setCharacterEncoding("utf8");
        filterChain.doFilter(servletRequest,servletResponse);
    }

    public void destroy() {

    }
}

登入拦截器

package filter;


import util.gongju;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class user implements Filter {
    public void init(FilterConfig filterConfig) throws ServletException {

    }

    public void doFilter(ServletRequest req, ServletResponse resp, FilterChain filterChain) throws IOException, ServletException {
       HttpServletRequest reqq = (HttpServletRequest) req;
        HttpServletResponse respp = (HttpServletResponse ) resp;
        Object attribute = reqq.getSession().getAttribute(gongju.USER_SESSION);
        if(attribute==null){

            respp.sendRedirect(reqq.getContextPath()+"/error.jsp");
        }
        filterChain.doFilter(req,resp);


    }

    public void destroy() {

    }
}

 

这篇关于狂神说java超市管理系统filten的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!