servlet request

servlet request

Components of the request:

  1. Request header

  2. Request line

  3. Blank line

  4. Body

    Request line = http protocol version + httpURL + submission method

Request submission method

  1. get commit

    1. Enter the URL in the address on the browser and press Enter

    2. Hyperlink submission method

    3. Method = "get" in the form, if there is no method, the default get is submitted

  2. post submission

    1. In the form method = "post"

Basically use the post submission method in the form

Difference between post / get submission method
feature get method post method
Submit data type text Text, binary
Submit data length <255 characters Unlimited
Visibility of submitted data Display as part of URL address The requested message body is not visible
Cache of submitted data Cached in browser URL history cache You will cache in your browser

Request method

// Request line information 

    // Get the version of the content submission method url http
     // Submission method 
        String method =    req.getMethod ();
     // url 
        String uri = req.getRequestURI ();
     // http version 
        String http_version = req.getProtocol ();
     // Get query string 
        String queryString = req.getQueryString (); 

    // Decode queryString 
        String new_queryString = URLDecoder.decode (queryString, "utf-8" ); 

    // Get the path of the web application 
        String contextPath =   req.getContextPath (); 

    // Get the URL path of access: protocol + ip + port number + uri
        StringBuffer url = req.getRequestURL (); 

    // Get the servlet path 
        String servletPath

     = req.getServletPath (); // Get the requested character encoding set 
        String encoding = req.getCharacterEncoding (); 

    // Get the visitor's ip address ( *********) 
         String ipaddress = req.getRemoteAddr (); 

// Request header information 
    
    // Get the information of the specified 
    header- > String req.getHeader ("Header name" ); 
        
        // Common Header name
         // Referer-> get the sending URL of the request (the anti-theft chain can be implemented)
         // User-Agent-> get the browser information (for example: version ...)
         // Cookie-> get the browser drawing information 
    
    // Get the names of all the heads-> Enumeration
    req.getHeaderNames();

 

other

  1. In WebServlet (name = "", value = {"", ""}); use an array for multiple values ​​in the annotation, use {} for the array in the direct

Guess you like

Origin www.cnblogs.com/-Archenemy-/p/12703306.html