JSP built-in objects

1. Introduction to built-in objects:

  JSP built-in objects are a set of objects created by the web container, built-in objects that can be used without using the new keyword.

 

2, JSP nine built-in objects:

  (1)out

  (2)request

  (3)response

  (4)session

  (5)application

  (6)Page / pageContext / exception / config

 

3. The request-response mode of the web program:

  User sends a request (request)

  The server responds to the user (response)

 

4. What is a buffer (Buffer):

  A buffer is an area of ​​memory used to store temporary data.

 

5. out object:

  The out object is an instance of the JspWriter class, which is a commonly used object for outputting content to the client.

  Common method:

  (1) void println() prints a string to the client;

  (2) void clear() clears the contents of the buffer, if called after flush, an exception will be thrown;

  (3) void clearBuffer() clears the contents of the buffer, if called after flush, no exception will be thrown;

  (4) void flush() outputs the buffer content to the client;

  (5) int getBufferSize() returns the size of the number of bytes in the buffer, or 0 if no buffer is set;

  (6) int getRemaining() returns how much is available in the buffer;

  (7) boolean isAutoFlush() returns when the buffer is full, whether to clear it automatically or throw an exception;

  (8) void close() closes the output stream;

Note: Q: Why is clear abnormal after Flush?

   A: When java uses streams, it will have a buffer, and send data according to a method that it thinks is more efficient: put the data to be sent into the buffer first, and then send the data at one time after the buffer is full. Rather than separate them one at a time.

  And flush() means to force the data in the buffer to be sent out without waiting until the buffer is full.

  Therefore, if the flush() method is not used when using the stream, there will be a problem that the other side of the stream cannot read the data in many cases, especially when the data is particularly small.

  So after flush(), the buffer is empty and clear will throw an exception.

  out.println();//Write to the buffer<br>

  When calling out.flush();, the buffer is flushed, the contents of the buffer are output, and the buffer is emptied<br>

  When calling out.clear();, the buffer is emptied, and the previous content in the buffer will not be output to the page<br>

  When the content in the buffer is full, the content in the buffer is automatically sent to the writing party;

  When the program terminates normally, the output buffer will be flushed automatically, but for example, file reading and writing, etc., the best practice is to call flush to flush the data in the buffer before closing the stream.

 

6. Form submission methods (get and post):

  (1) get: Submit the data through the URL in plain text, and the data can be seen in the URL. Submitted data should be no larger than 2KB. Less secure but more efficient than the post method. It is suitable for submitting data with a small amount of data and low security. For example: search, query and other functions.

  (2) post: encapsulate the information submitted by the user in the HTML HEADER. It is suitable for submitting user information with a large amount of data and high security. For example: registration, modification, upload and other functions.

 

7. The request object:

  The client's request information is encapsulated in the request object, through which the client's needs can be learned and then a response can be made. It is an instance of the HttpServletRequest class. The request object has a request field, that is, the object is valid until the client's request is completed.

  Common method:

  (1) String getParameter(String name) returns the parameter value of the parameter specified by name;

  (2) String[ ] getParameterValues(String name) returns an array containing all the values ​​of the parameter name;

  (3) void setAttribute(String, Object); store the attributes in this request;

  (4) object getAttribute(String name); returns the attribute value of the specified attribute;

  (5) String getContentType(); Get the MIME type of the request body;

  (6) String getProtocol(); Returns the protocol type and version number used for the request;

  (7) String getServerName(); Returns the hostname of the server that accepts the request;

     (8) int getServerPort() returns the port number used by the server to accept this request;

  (9) String getCharacterEncoding() returns the character encoding method;

  (10) void setCharacterEncoding() Set the requested character encoding;

  (11) int getContentLength() returns the length of the request body (in bytes)

  (12) String getRemoteAddr() returns the IP address of the client that sent this request;

  (13) String getRealPath(String path) returns the real path of a virtual path;

  (14) String request.getContextPath() returns the context path;

  

   

 

 

    

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325011956&siteId=291194637