package example_1_tg;

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;

public class Requestfilter extends HttpServlet implements Filter {
    private FilterConfig filterConfig;
    public void init(FilterConfig filterConfig) throws
            ServletException {
        this.filterConfig = filterConfig;
    }

    public void doFilter(ServletRequest request, ServletResponse
                         response, FilterChain filterChain) {
        String username = "anne_park";
        String firstname = "Anne";
        String lastname = "Park";
        HttpSession
                ses = ((HttpServletRequest) request).getSession(true);
        ses.setAttribute("username", username);
        ses.setAttribute("firstname", firstname);
        ses.setAttribute("lastname", lastname);
        try {
            filterChain.doFilter(request, response);
        } catch (ServletException sx) {
            filterConfig.getServletContext().log(sx.getMessage());
        } catch (IOException iox) {
            filterConfig.getServletContext().log(iox.getMessage());
        }
    }

    public void destroy() {
    }
}
