Introduction to JSP page Jump and request forwarding

Source: Internet
Author: User

JSP page Jump and request forwarding favorites

1. response. sendRedirect (url)

It refers to request redirection. The original page parameters cannot be obtained here, that is, the return value is null using request. getParameter ("param ")

2. forward request refers to the transfer of the request and response object of the original page to a new page. Therefore, the new and old pages have the same request and response object. In this way, request. getParameter ("param") can get the corresponding value.

3. differentiate between ServletContext. getRequestDispatcher and ServletRequest. getRequestDispatcher.

The ServletContext. getRequestDispatcher path must be an absolute path relative to the context.

ServletRequest. getRequestDispatcher can be relative or absolute

4. Note that the address bar displayed in the browser after forwarding by Using forward is not forwarded. Such as test. jsp to good. jsp forwarding, the address bar displays test. jsp. this is because forward is performed on the server, and the browser does not know it at all, and redirection is performed on the client, so response is used. sentRedirect ("red. jsp ") will direct to red. jsp. This comes to mind the index. jsp requests servlet, then forward forawrd in servlet to another red. jsp page, but when you view the results, the address bar displays only the servlet name rather than red. jsp. If you want to know the name of the final page, you only need to check the code.

Reference it:

Four Methods for server redirection:

1. getRequestDispatcher () of ServletContext ()

2. getNamedDispatcher () of ServletContext ()

3. getRequestDispatcher () of ServletRequest ()

4. ServletResponse's sendRedirect () is switched.

1.2.3 => forward () 4. sendRedirect ()

Use the forward method because it is more efficient. The sendRedirect () method of ServletResponse is used only when the forward method cannot be used, for example, to be switched to a non-local web application.

<Jsp: fordward> comparison with sendRedirect

Although both the <jsp: fordward> and sendRedirect methods can redirect the web page browsed by the browser to another web page, the two are not the same in principle.

A. <jsp: fordward>: the action is to use the servo end to output data to the buffer zone. The data output is canceled before the previous webpage is output to the client, then output the information of another web page to re-export the browser.

Advantage: You can share the variables in the request object between the two webpages.

B. sendRedirect: the action is to issue a re-import command to the browser through the HTTP Header. Therefore, the server-side buffer is not involved.

However, because the sendRedirect method acts on the client, the webpage cannot share the variables in the request object before and after the re-import.
Solution: response.sendredirect(inclusendredirect.htm? Name = sparkwu & E-Mail = spark.wu@cobra-tech.com ")

  1. JSP message board source code operation implementation
  2. Detailed description of JSP commands and script elements
  3. Configuration of three connection strings in JSP
  4. Which of ASP. NET, JSP, and PHP is better?
  5. JSP-related software

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.