Response and request base of Javaweb

Source: Internet
Author: User
Tags get ip

1 Response

A Send error response

. Senterror ()///with one parameter and 2 parameters

b Setting the response header

. SetHeader (String name,string value)//There are several more, here only one

Response Redirection: 302 procedure?

//         302The first one//        response.setstatus (302); //         response.setheader ("Location", Request.getcontextpath () + "/index.jsp"); //         302 The  Second          response.sendredirect ("/pra/index.jsp");

The response is timed to refresh the specified page (equivalent to timed redirection):

//         regularly updated            response.setheader ("Refresh", "5;url=" +request.getcontextpath () + "/index.jsp");

Byte stream/character stream of C-response body

D Request's Domain attribute its with session and application is called the three domains, each domain has its own setattribute () getattribute () RemoveAttribute () method

E-Response encoding

Server to set setcharacterencording ("Utf-8") and setContentType ("Text/html;characster=utf-8") when sending

This allows the browser (client) to be acquired before it is properly encoded

2 Request

A Get Ip/request method/browser type (identify user)/refer anti-theft chain

//         get the hostname and other things //        System.out.println (request.getremoteaddr ()); //         System.out.println (Request.getmethod ()); //         System.out.println (request.getlocaladdr ()); //         System.out.println (Request.getheader ("user-agent")); //         System.out.println (Request.getheader ("Refer"));

b How to get URLs

C Request parameters can be obtained regardless of whether get or post

Get: Parameter after URL

http://localhost:8080/pra/Aservlet?one=123&two=3213//Parameters and URLs used? Connection, between parameters with & connection, parameter name and value = Connection

Post: The parameter is in the request body

D forward/include Request forwarding process?

Forward: Only the header information of the previous servlet is retained, not the body, the first request body cannot be too large

Includ: Retains the header of the previous servlet and retains its body

Forwark/include and redirect relationships?

Redirect: Servlet may be changed in different requests (request and response)

Forward/include: Requests and response objects do not change in the same request

F Request Encoding

? When submitting a form on a page, if your page is of type utf-8, then the parameter you pass is the Utf-8 type.

? Post request: setcharacterencording ("Utf-8") and setContentType ("Text/html;characster=utf-8")

? GET Request: We use the Java string to do it ourselves.

    

    

  

    

Javaweb Response and Request Basics

Related Article

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.