リクエスト、レスポンス、セッション

  • 作成者:ayuan0625
  • 編集回数:6次
  • 最終更新:FRInternational 于 2021-05-07
  • 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: 帳票機能応用
    既に最初
    既に最後
    • Helpful
    • Not helpful
    • Only read