In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article will explain in detail what are the hidden objects in JSP. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.
1. Page object
The page object represents the JSP itself, or more accurately, the translated Servlet of the JSP, which can call the methods defined by the Servlet class.
2. Config object
Some of the original Servlet data structures are stored in the config object.
The config object is implemented in the javax.servlet.ServletConfig interface and has the following four methods:
Public String getInitParameter (name) public java.util.Enumeration getInitParameterNames () public ServletContext getServletContext () public Sring getServletName ()
3. Request object
The request object contains information about all requests, such as the source of the request, the header, the cookies, and the parameter values associated with the request, and so on.
The methods provided by the request object that implement the javax.servlet.http.HttpServletRequest interface can be divided into four categories:
1. Methods for storing and getting attributes
Void setAttribute (String name, Object value) sets the value of the name attribute to value Enumeration getAttributeNamesInScope (int scope) gets all scope range attributes Object getAttribute (String name) gets the value of the name attribute void removeAttribute (String name) removes the value of the name attribute
two。 The method of getting the request parameters
String getParameter (String name) gets the parameter value of name Enumeration getParameterNames () gets all the parameter names String [] getParameterValues (String name) gets all the parameter values of name Map getParameterMap () gets a Map of the required parameter
3. A method that can get the request HTTP header
String getHeader (String name) get name header Enumeration getHeaderNames () get all header names Enumeration getHeaders (String name) get all name header int getIntHeader (String name) get integer type name header long getDateHeader (String name) get date type name header Cookie [] getCookies () get cookies related to the request
4. Other methods
String getContextPath () gets the Context path (that is, the name of the station) String getMethod () gets the HTTP method (GET, POST) String getProtocol () gets the protocol HTTP/1.1, HTTP/1.0) String getQueryString () used to get the requested parameter string, however, the HTTP method must get the requested URL for GET String getRequestedSessionId () to get the client's Session ID String getRequestURI () But does not include the requested parameter string String getRemoteAddr () to get the user's IP address String getRemoteHost () to get the user's host name int getRemotePort () to get the user's host port String getRemoteUser () to get the user's name void etCharacterEncoding (String encoding) to set the coding format to solve the problem of the form passing Chinese
4. Response object
The response object mainly passes the result of the data processed by JSP back to the client.
The response object implements the javax.servlet.http.HttpServletResponse interface. Methods provided by the response object.
1. The method of setting the meter header
Void addCookie (Cookie cookie) add cookie void addDateHeader (String name, long date) add long type value to name header void addHeader (String name, String value) add String type value to name header void addIntHeader (String name, int value) add int type value to name header void setDateHeader (String name, long date) specify long type value to name header void setHeader (String name, String value) specify String type value to name header void setIntHeader (String name Int value) specifies the value of type int to the name header
two。 The method of setting response status code
Void sendError (int sc) transfer status code (status code) void sendError (int sc, String msg) transmission status code and error message void setStatus (int sc) set status code
3. Method used for URL rewriting (rewriting)
String encodeRedirectURL (String url) encodes URL using the sendRedirect () method
5. Out object
The out object can output the results to a web page.
Out is mainly used to control the buffer (buffer) and output stream (output stream) that manage the output.
Void clear () clears the contents of the output buffer void clearBuffer () clears the contents of the output buffer void close () closes the output stream, clears all contents int getBufferSize () gets the current buffer size (KB) int getRemaining () takes the remaining buffer size (KB) boolean isAutoFlush () returns true indicates that the buffer will be cleared automatically when the buffer is full False indicates that it will not be cleared automatically and exception handling will be generated.
VI. Session object
The session object represents the current session (session) status of individual users.
The session object implements the javax.servlet.http.HttpSession interface, the methods provided by the HttpSession interface
Long getCreationTime () gets the time when the session is generated, in milliseconds String getId () gets the ID long getLastAccessedTime of session () gets the user * the time that the user sends the request through this session long getMaxInactiveInterval () gets the time of inactivity of * session. If the time exceeds this time, session will invalidate void invalidate () and cancel the session object. And completely discard the contents of the object stored in boolean isNew () to determine whether session sets * session inactivity time for the "new" void setMaxInactiveInterval (int interval). If it exceeds this time, session will become invalid.
7. Application object
Application objects are most commonly used to access information in the environment.
Because the information of the environment is usually stored in ServletContext, application objects are often used to access the information in ServletContext.
The application object implements the javax.servlet.ServletContext interface, the methods provided by the ServletContext interface container
Int getMajorVersion () get Container major Servlet API version int getMinorVersion () get Container minor Servlet API version String getServerInfo () get the name and version of Container String getMimeType (String file) get the MIME type of the specified file ServletContext getContext (String uripath) get the Application context String getRealPath (String path) of the specified Local URL get the absolute path of the local path void log (String message) write the information to void log (String message) in the log file Throwable throwable) write the exception information generated by stack trace into the log file
8. PageContext object
PageContext objects can access other implicit objects.
The 1.pageContext object accesses other implicit object properties, in which case you need to specify a range of parameters.
Object getAttribute (String name, int scope) Enumeration getAttributeNamesInScope (int scope) void removeAttribute (String name, int scope) void setAttribute (String name, Object value, int scope)
There are four range parameters, which represent four ranges: PAGE_SCOPE, REQUEST_SCOPE, SESSION_SCOPE, and APPLICATION_SCOPE
Methods of getting other implied objects by 2.PageContext object
Exception getException () returns the exception of the current web page, but this page should be error page
JspWriter getOut () returns the output stream of the current web page, for example: out
Object getPage () returns the Servlet entity (instance) of the current web page, for example: page
ServletRequest getRequest () returns the request of the current web page, for example: request
ServletResponse getResponse () returns the response of the current web page, for example: response
ServletConfig getServletConfig () returns the current ServletConfig object of this page, such as config
ServletContext getServletContext () returns the current execution environment (context) of this page, for example: application
HttpSession getSession () returns a session (session) that is associated with the current web page, for example: session
The 3.PageContext object provides methods to get properties
Object getAttribute (String name, int scope) returns the name attribute. The scope is the attribute object of scope. The return type is Object.
Enumeration getAttributeNamesInScope (int scope) returns the names of all attributes whose range is scope, and the return type is Enumeration
Int getAttributesScope (String name) returns a range of attributes whose name is name
Void removeAttribute (String name) removes an attribute object with an attribute name of name
Void removeAttribute (String name, int scope) removes a property object with an attribute name of name and a range of scope
Void setAttribute (String name, Object value, int scope) specifies that the name of the property object is name, the value is value, and the range is scope.
Object findAttribute (String name) looks for an attribute object whose attribute name is name in all scopes
IX. Exception object
To use the exception object, you must set it in the page instruction. Before you can use it.
Three methods provided by exception:
GetMessage ()
GetLocalizedMessage (),
PrintStackTrace (new java.io.PrintWriter (out))
This is the end of this article on "what are the hidden objects in JSP?". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.