zoukankan      html  css  js  c++  java
  • 会话与过滤器

    会话跟踪
      Cookie机制
       javax.sevlet.http.Cookie
       request.getCookie();
       response.addCookie();
       保存中文:
        Cookie cookie=new Cookie(URLEncoder.encode("姓名","UTF-8"),URLEncoder.encode("邓远奇","UTF-8"));
       保存二进制图片:
        File file=new File(image.path);
        byte [] binary=new bate[(int)file.lenth];
        InputStream in=this.getServletContext().getResourceAsStream(file.getName());
        in.read(binary);
        in.close;
        String content=BASE64Encoder.class.newInstance().encode(binary);
        Cookie cookie=new Cookie("file",content);
     
     过滤器Filter
      Filter:
       用户在servlet之外对request/response进行修改
       一个Filter必须实现javax.servlet.Filter接口,该接口有三个方法:
        public void init(FilterConfig config){};
        public void doFilter(Request request,Response response,FilterChain chain){};
         在doFilter()方法中一定要执行chain.doFilter(request,response,chain);
        public void destory();
       Filter配置:
        在web.xml
         <filter>
          <filter-name></filter-name>
          <filter-class></filter-class>
          <init-param></init-param>
         </filter>
         <filter-mapping>
          <filter-name></filter-name>
          <url-pattern></url-pattern>
          <dispathcher>REQUEST/RESPONSE </dispathcher>  //配置到达servlet的方式
         </filter-mapping>
       字符编码过滤器:
        request.setCharacterEncoding("UTF-8");
        response.setCharacterEncoding("UTF-8");
       登陆过滤器:
        session.getAttribute("username");  //从session中取出username判断是否为null

  • 相关阅读:
    【Jquery】根据元素个数给予宽度
    【Jquery】判断宽度跳转
    【CSS】滚动条样式
    关于vue在列表展示数据的时候,选择更改其中一项,数据跟着实时变动的问题
    JAVA基础知识
    华为机试 字符串分隔
    华为机试 计算字符个数
    华为机试 字符串最后一个单词的长度
    简单构造 Ext.tree 树例子
    Ext.form.Label组件动态设置html值
  • 原文地址:https://www.cnblogs.com/dengyuanqi/p/6378335.html
Copyright © 2011-2022 走看看