• JSP 中的 Request 和 Response 对象


      客户端的请求信息被封装在request对象中,通过它才能了解到客户的需求,然后做出响应。它是HttpServletRequest类的实例;response对象包含了响应客户请求的有关信息,但在JSP中很少直接用到它。它是HttpServletResponse类的实例。
      今天需要用的时候到处找了,今天记录下来备查。

    一、Request 

    object getAttribute(String name)    //返回指定属性的属性值
    Enumeration getAttributeNames()     //返回所有可用属性名的枚举
    String getCharacterEncoding()       //返回字符编码方式
    int getContentLength()              //返回请求体的长度(以字节数)
    String getContentType()             //得到请求体的MIME类型
    ServletInputStream getInputStream() //得到请求体中一行的二进制流
    String getParameter(String name)    //返回name指定参数的参数值
    Enumeration getParameterNames()     //返回可用参数名的枚举
    String[] getParameterValues(String name)    //返回包含参数name的所有值的数组
    String getProtocol()                //返回请求用的协议类型及版本号
    String getScheme()                  //返回请求用的计划名,如:http.https及ftp等
    String getServerName()              //返回接受请求的服务器主机名
    int getServerPort()                 //返回服务器接受此请求所用的端口号
    BufferedReader getReader()          //返回解码过了的请求体
    String getRemoteAddr()              //返回发送此请求的客户端IP地址
    String getRemoteHost()              //返回发送此请求的客户端主机名
    void setAttribute(String key,Object obj)    //设置属性的属性值
    String getRealPath(String path)     //返回一虚拟路径的真实路径

    eg:

    request.getScheme()         // http
    request.getServerName()     // localhost
    request.getServerPort()        // 8080
    request.getContextPath()     // vote
    request.getProtocol()         // HTTP/1.1
    request.getRemoteAddr()     // 127.0.0.1
    request.getRemoteHost()     // 127.0.0.1
    request.getRemotePort()     // 1316
    request.getRequestURI()     // /vote/test.jsp
    request.getRequestURL()     // http://localhost:8080/vote/test.jsp
    request.getServletPath()     // /test.jsp

    二、response

    String getCharacterEncoding()            //返回响应用的是何种字符编码 
    ServletOutputStream getOutputStream()    //返回响应的一个二进制输出流 
    PrintWriter getWriter()                  //返回可以向客户端输出字符的一个对象 
    void setContentLength(int len)           //设置响应头长度 
    void setContentType(String type)         //设置响应的MIME类型 
    sendRedirect(java.lang.String location)  //重新定向客户端的请求

    参考:

    [1] 大蒜披萨.JSP开发中request对象URL方法对照表.http://blog.sina.com.cn/s/blog_5c0522dd0100gzpj.html

    [2] JSP内置对象简介:Request和Response.http://developer.51cto.com/art/200907/133441.htm

  • 相关阅读:
    IDAPython学习(一)
    自动提取文件系统---binwalk(一)
    Scapy Fuzz实现——S7协议从建连到“正常交流“(一)
    工控系统的指纹识别技术
    揭秘VxWorks——直击物联网安全罩门
    VxWorks Fuzzing 之道:VxWorks 工控实时操作系统漏洞挖掘调试与利用揭秘
    路由器文件系统与提取
    python 调试技巧
    拿下id_rsa
    elasticsearch 7.1 401 Unauthorized
  • 原文地址:https://www.cnblogs.com/ccdc/p/3483180.html
Copyright © 2020-2023  润新知