request、response and session

  • Last update:May 07, 2021
  • I. request object

    The object encapsulates the information submitted by the user, and the encapsulated information can be obtained by calling the corresponding method of the object, that is, the information submitted by the user can be obtained by using the object.

    request.getAttribute("key") can get the JSP page and save it in Value. In actual storage, the key and value are stored in a hash table, so the key of String given here will find the corresponding value in the hash table.

    When request.setAttribute(key, value) is used to transfer values between different pages, only one request will be made from a.jsp to b.jsp. If there is a second request after that, the request will lose its scope and pass again. It is necessary to set request.setAttribute(key, value) again or use the forward() method of request to jump (because it is a request). Using session.setAttribute() will always keep this value in a process.

    II. response object

    Contains information about responding to customer requests, but it is rarely used directly in JSP. It is an instance of the HttpServletResponse class. The response object is used to dynamically respond to client requests, control the information sent to the user, and dynamically generate responses. Before responding to the client's request, you can generally set the encoding format of the client's response to prevent garbled characters on the client. response.setCharacterEncoding("GBK");

    response can be redirected to this website or to other websites; during the redirection process, it is equivalent to re-entering the URL in the URL address bar. This is the second request, so the data saved in request and response is just doesn't exist anymore.

    III. Session object

    Refers to a session between the client and the server, starting from a WebApplication where the client connects to the server, until the client disconnects from the server. It is an instance of the HttpSession class.

    Session: Used to save the dedicated information of each user. The information in the session is stored in the memory of the Web server, and the amount of data stored can be large or small. When the Session times out or is closed, the saved data information will be automatically released. For a small amount of data, Session object storage is still a good choice.


    Attachment List


    Theme: Report Features
    • Helpful
    • Not helpful
    • Only read

    滑鼠選中內容,快速回饋問題

    滑鼠選中存在疑惑的內容,即可快速回饋問題,我們將會跟進處理。

    不再提示

    10s後關閉

    Get
    Help
    Online Support
    Professional technical support is provided to quickly help you solve problems.
    Online support is available from 9:00-12:00 and 13:30-17:30 on weekdays.
    Page Feedback
    You can provide suggestions and feedback for the current web page.
    Pre-Sales Consultation
    Business Consultation
    Business: international@fanruan.com
    Support: support@fanruan.com
    Page Feedback
    *Problem Type
    Cannot be empty
    Problem Description
    0/1000
    Cannot be empty

    Submitted successfully

    Network busy