In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
Editor to share with you what the implied JSP objects are, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!
1. Page object
The page object represents the JSP object, or more accurately, the translated Servlet of 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 properties
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 Enumeration of name
GetParameterNames () gets all the parameter names String []
GetParameterValues (String name) gets the parameter values of all name
Map getParameterMap () gets a Map that requires a parameter
3. A method that can get the request HTTP header
String getHeader (String name) gets the header of name
Enumeration getHeaderNames () gets all the header names
Enumeration getHeaders (String name) gets all name headers
Int getIntHeader (String name) gets the header of the integer type name
Long getDateHeader (String name) gets the header of the date type name
Cookie [] getCookies () gets the cookies associated with the request
4. Other methods
String getContextPath () gets the Context path (that is, the site name)
The method of obtaining HTTP by String getMethod () (GET, POST)
String getProtocol () to get the protocols used HTTP/1.1, HTTP/1.0)
String getQueryString () gets the requested parameter string, but the method of HTTP must be GET
String getRequestedSessionId () gets the Session ID of the client
String getRequestURI () gets the requested URL, but does not include the requested parameter string
String getRemoteAddr () gets the user's IP address
String getRemoteHost () gets the user's host name
Int getRemotePort () gets the user's host port
String getRemoteUser () gets the user's name
Void etCharacterEncoding (String encoding) sets the encoding format to solve the problem of transmitting Chinese in the form.
4. Response object
The response object mainly passes the result of the data processed by the JSP object 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
New cookie for void addCookie (Cookie cookie)
Void addDateHeader (String name, long date) adds a value of type long to the name header
Void addHeader (String name, String value) adds a value of type String to the name header
Void addIntHeader (String name, int value) adds a value of type int to the name header
Void setDateHeader (String name, long date) specifies the value of type long to the name header
Void setHeader (String name, String value) specifies the value of type String to the 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) Transmission status Code (status code)
Void sendError (int sc, String msg) transmits status codes and error messages
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 and clears all contents
Int getBufferSize () gets the current buffer size (KB)
Int getRemaining () gets the buffer size left after the current use (KB)
Boolean isAutoFlush () return 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 of session generation (in milliseconds)
String getId () gets the ID of session
Long getLastAccessedTime () gets the time when the user sent the request through this session
Long getMaxInactiveInterval () acquires * session inactivity time. If this time is exceeded, session will become invalid.
Void invalidate () cancels the session object and completely discards the contents stored in the object
Boolean isNew () determines whether session is "new"
Void setMaxInactiveInterval (int interval) sets the time for session to be inactive. If this time is exceeded, 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 () gets the main Servlet API version of Container
Int getMinorVersion () gets the minor Servlet API version of Container
String getServerInfo () gets the name and version of Container
String getMimeType (String file) gets the MIME type of the specified file
ServletContext getContext (String uripath) gets the Application context of the specified Local URL
String getRealPath (String path) gets the absolute path of the local side path
Void log (String message) writes information to the log file
Void log (String message, Throwable throwable) writes the abnormal 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))
The above is all the content of the article "what are the implied JSP objects?" Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
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.