zoukankan      html  css  js  c++  java
  • request 、response和session的区别

    request:

    1、request.getParameter("key")接受的是来自客户登陆端的数据,接受的是post或get方式传送的value。

    2、请求的默认字符集是ISO-8859-1,不支持中文,需要new String (request.getParameter(key).getbyte("ISO-8859-1"),"UTF-8")进行转码。

    3、可以给请求对象添加数据但是必须通过forward进行转发。

    4、request.setAttribute(key,object)--发送对象,request.getAttribute(key,object)--接受对象。

    5、接收cookie  Cookie[] ck = request.getCookies();获取值--遍历for(Cookie cks:ck){out.print(URLDecoder.decode("编码后的字符串"))}。

    response

    1、发送cookie--添加cookie对象:Cookie ck=new Cookie("key","value");addCookie(Cookie对象)

    2、跳转页面--sendRedirect("跳转地址")--直接跳转。

    3、setHeader("refresh","秒数;URL=跳转地址")--定时跳转页面。

    4、setHeader("refresh","秒数")--定时刷新页面。

    5、没有设置属性值的方法。没有setAttribute的方法。

    6、setheader("cache-control","no-cache")--禁止浏览器缓存

    session:

    1、setAttribute("key",object)--设置属性值。getAttribute("key")--获取属性值--返回Object类型需要将获取到的值用toString()方法。

    2、session.invalidate()--销毁session--一般退出登录时用。

    3、setMaxInactiveInterval(秒数)--设置超时秒数。

  • 相关阅读:
    linux 中的vim的配置文件的位置
    centos find
    multi-cursor
    ctrlsf插件
    Vim的可视模式
    Vim的tagbar插件
    Vim的tag系统
    ~/.ctag的作用与配置
    在Vim里使用gtags-cscope
    查看Vim的option变量的值
  • 原文地址:https://www.cnblogs.com/diaozhaojian/p/6017451.html
Copyright © 2011-2022 走看看