Two ways to jump to a servlet page and three ways to pass parameters

Foreword: Page jump involves the jump from the Java background to the front page, and the jump between the background pages. The way of passing parameters involves the doGet method and the doPost method in the servlet. See other essays.

1. Page jump  

  1. Request forwarding:

    (1) Use the requestDispatcher object:

      转发格式:request.getRequestDispatcher("path").forward(response,request)

    (2) Use jsp action elements:

      <jsp:forward page=""/>

  2. Request redirection:

    Use the rsendRedirect method of the response:

      Redirect format: response.sendRedirect( "path");

  3. The difference between request forwarding and request redirection:

  

 

    (From: https://www.cnblogs.com/chenkeyu/p/7230714.html)

    (1) The request is forwarded as an internal jump in the server. After one jump, the client receives the result without changing the url address, while the request redirection is jumped twice, which not only returns the result to the client, but also makes the client's url address Change. 

    (2) The request forwarding is an internal jump, the object of the page request always exists, and the request redirection will end the request of the previous page.

    (3) The request object method setAttribute("name", value) is used to pass the parameters of the request forwarding, and the url pass parameters can be used to request redirection.

Second, the way of passing parameters:

  1. Form form to pass parameters

  2. url pass parameters

  3. Built-in object parameters: setAttrribute method of session, request, application, etc.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325075705&siteId=291194637