JavaWeb——HttpServletResponse

介绍

  HttpServletResponse类用于封装Http响应消息

 

方法

  void setHeader( String name,String value )

    参数:

      String name:字段名称

      String value:值

    返回值:void

    返回值意义:无

    作用:设置响应头

 

  void setContentType(String type)

    参数:

      String type:输出内容的类型

    返回值:void

    返回值意义:无

    作用:设置响应体的类型,同时设置encoding,这个或CharacterEncoding必须设置一个utf-8。因为编码会在服务器一次,会在浏览器解码一次。服务器默认ISO-8890,浏览器默认utf-8。所以服务器至少设计一个(text/html;charset=utf-8)

   

  void setCharacterEncoding(String charset)

    参数:

      String charset:响应体的字符集编码

    返回值:void

    返回值意义:无

    作用:设置响应体的字符集编码

 

  ServletOutputStream getOutputStream()

    参数:无

    返回值:ServletOutputStream对象

    返回值意义:返回输出流对象

    作用:获取输出流对象,可以向客户端输出二进制数据

    

  PrintWriter getWriter()

    参数:无

    返回值:PrintWriter对象

    返回值意义:返回字符输出流对象

    作用:返回可将字符文本发送到客户端的 PrintWriter 对象

    

  (

  PrintWriter printWriter对象,方法write( String string )

  将内容回复到客户端。 可以多次调用,结果同一发送

  )

  PrintWriter , sendRedict() , ServletOutputStream 只能用一个

 

  void sendRedirect(String url)

    参数:String url

    返回值:无

    返回值意义:无

    作用:请求重定向到url指向的网址

 

  

  

  

posted @ 2021-08-10 12:27  remix_alone  阅读(118)  评论(0)    收藏  举报