Javaweb notes Three

Source: Internet
Author: User
Tags browser cache

If you write an annotation, you don't have to register it in Web. xml
@WebServlet (urlpatterns= "/my", name= "my", loadonstartup=1,initparams={@WebInitParam (name= "AAA", value= "DDD")})

HTTP status code: (404: Client exception; 500: Server exception; 302: redirect exception; 200: Access normal 405:: The request is not in the right way)
100-199: Represents an informational code that indicates other actions that the client should take, and the request is in progress.
200-299: Indicates a successful customer request.
300-399: Indicates the new address for the resource file that was removed.
400-499: Represents an error thrown by the client.
500-599: Represents an error raised by the server side.
Doget () must be overridden, otherwise the parent class's Response.senderror (404, "No page") will be called;
Status line must be set before output message (status line--Response header--blank line-message body)

The response header is used by the server to tell the client about server-related information. Can be set with Response.setheader (). However, according to the servlet specification, the client browser can only identify specific
The response header, so the settings of the response header are usually encapsulated as a response method. For example: SetHeader (), setContentType (), Addcookie (), Sendredirect (), Addsession ()
Response.setheader ("Content-type", "text/html;charset=utf-8") = = = Response.setcontenttype ("text/html;charset= Utf-8 ");

There are two ways to respond to the message body content: Returning the custom content requires using getwriter () to transfer plain text: PrintWriter out = Response.getwriter ();
or the Getoutputstream () method transmits binary content: OutputStream out = Response.getoutputstream ();

Verification code to prevent users from constantly violent login, mainly for security reasons.
"/testweb/checkcode?a=" +math.random () clears the browser cache
Randomly generates random numbers from the server and does not fetch from the cache
The browser has a cache, and when the client browser sends a request to the server, it caches the downloaded content in the browser.
If the client requests the same page of the server again, it will first see if there are any downloaded resources in the browser cache.
If there is, the resource will be fetched from the browser cache if not, then downloaded from the server
$ ("#codeImg"). attr ("src", "/testweb/checkcode?a=" +math.random ());

REDIRECT Workflow:
When a client makes a request to the server and calls Response.sendredirect () generates a response, it generates a 302 status code, generating a location response header that indicates in the location response header
The new address. After the client browser receives the response information, it discovers the 302 status code, reads the location response header information, and sends a second request to the server.
Java.lang.IllegalStateException:Cannot call Sendredirect () after the response have been committed//redirect cannot be used two times

The client sends a GET request:
1, users click on a hyperlink on the Web page 2, the user submits a form on the Web page (method= "Get", the default is get Submit) 3, the user enters the URL address in the browser address bar and enter
The client sends a POST request:
<form method= "POST" >
Use the Post method when sending big data, use the Post method when uploading a file, use the Post method when sending a user name, password, or other confidential information

The benefit of GET requests is access to static resources, where post requests are primarily used to submit forms and upload files
The difference between get and post:
1, the difference between the stream format:
The Get method has only a request line, a request header, a blank line, and no message body. Append the form data after the request line URL.
The Post method includes the request line, the request header, the blank line, the message body. Describes the form data in the message body.
2, the use of the difference:
Get is used for resource lookups and post for data transfer.
3, the difference of transmission performance:
The Get method can only transfer text data, and post can transfer text and binary data.
Get mode cannot transfer big data, post can.
The GET request data is displayed in the Address bar, and the post data in the message body is not displayed in the Address bar, which is relatively secure.
Get caches data, post is not cached.

URL contains URI

Javaweb notes Three

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.