Brief description of three relationships between Java Web Components

Source: Internet
Author: User

Three association relationships between Java Web Components:

1. Request Forwarding

2.URL redirect

3. Contains

Request Forwarding:

Allows forwarding of requests to other Web Components in the same application.

This technique is commonly used for the servlet process controller of the Web application control layer, which examines the HTTP request data and forwards the request to the appropriate target component, the target build performs a specific request processing operation, and generates the response results.

Add the following code to the JSP page by adding the servlet:

<jap:forward page="hello.jsp"/>
RequestDispatcher rd=request.geRequestDispatcher("hello.jsp");
//Forward to requested URL
rd.forward(request,response);

Request Redirection:

The same HttpServletRequest object cannot be used between the redirected source component and the target component, so shared data within the request scope cannot be shared.

The service () method in the servlet adds the following code:

Response.sendredirect ("url");

Contains:

The source and target components that contain the relationship share a HttpServletRequest object, so they shared the shared data in the request scope.

Add code to the JSP page:

<%@ include file="header.jsp"%>
<%@ include file="main.jsp"%>
<%@ include file="footer.jsp"%>
servlet的service()方法中加入下面代码:
RequestDispatcher rd;
rd=req.getRequestDispatcher("/header.jsp");
rd.include(req,resp);
rd=req.getRequestDispatcher("/main.jsp");
rd.include(req,resp);
rd=req.getRequestDispatcher("/footer.jsp");
rd.include(req,resp);

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.