当前位置: 代码迷 >> 综合 >> 13、过滤器、监听器常见应用
  详细解决方案

13、过滤器、监听器常见应用

热度:97   发布时间:2024-01-29 10:09:39.0

监听器:GUI编程中经常使用;

public class TestPanel {public static void main(String[] args) {Frame frame = new Frame("中秋节快乐");  //新建一个窗体Panel panel = new Panel(null); //面板frame.setLayout(null); //设置窗体的布局
?frame.setBounds(300,300,500,500);frame.setBackground(new Color(0,0,255)); //设置背景颜色
?panel.setBounds(50,50,300,300);panel.setBackground(new Color(0,255,0)); //设置背景颜色
?frame.add(panel);
?frame.setVisible(true);
?//监听事件,监听关闭事件frame.addWindowListener(new WindowAdapter() {@Overridepublic void windowClosing(WindowEvent e) {super.windowClosing(e);}});
?
?}
}

 

用户登录之后才能进入主页!用户注销后就不能进入主页了!

  1. 用户登录之后,向Sesison中放入用户的数据

  2. 进入主页的时候要判断用户是否已经登录;要求:在过滤器中实现!

    HttpServletRequest request = (HttpServletRequest) req;
    HttpServletResponse response = (HttpServletResponse) resp;
    ?
    if (request.getSession().getAttribute(Constant.USER_SESSION)==null){response.sendRedirect("/error.jsp");
    }
    ?
    chain.doFilter(request,response);

     

  相关解决方案