Servlet | Request request forwarding and resource sharing


1. Request forwarding

Request forwarding is an 服务器内部existing resource jump method

step:

  1. requestGet request forwarder object through object:
    RequestDispatcher getRequestDispatcher(String path); 
    
  2. Use RequestDispatcherobjects to forward:
    forward(ServletRequest request,ServletResponse response);
    

Generally use chain programming to write directly into one line:

request.getRequestDispatcher(String path).forward(request,response);

Features:

  • Request forwarding browser address bar path does not change
  • Can only be forwarded to the internal resources of the current server
  • Forwarding is a request

2. Sharing resources

Domain object: an object with a scope that can share data within the scope

requestDomain: Represents the scope of a request, and is generally used to share data among multiple resources requested for forwarding

method:

  • void setAttribute(String name,Object obj):Storing data
  • Object getAttribute(String name): Get value by key
  • void romoveAttribute(String name): Remove key-value pairs by key

Guess you like

Origin blog.csdn.net/lesileqin/article/details/112527458