In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces what built-in object methods JSP has, which can be used for reference by interested friends. I hope you can learn a lot after reading this article.
1.request object
The request information of the client is encapsulated in the request object, through which we can understand the customer's needs and then respond. It is an instance of the HttpServletRequest class.
1 object getAttribute (String name) returns the property value of the specified property
[/ color] 2 Enumeration getAttributeNames () returns an enumeration of all available property names
3 String getCharacterEncoding () returns the character encoding method
4 int getContentLength () returns the length of the request body (in bytes)
5 String getContentType () gets the MIME type of the request body
6 ServletInputStream getInputStream () gets the binary stream of one line in the request body
7 String getParameter (String name) returns the parameter value of the parameter specified by name
8 Enumeration getParameterNames () returns an enumeration of available parameter names
9 String [] getParameterValues (String name) returns an array containing all values of the parameter name
10 String getProtocol () returns the protocol type and version number used for the request
11 String getScheme () returns the name of the plan used for the request, such as http.https, ftp, etc.
12 String getServerName () returns the hostname of the server that accepted the request
13 int getServerPort () returns the port number used by the server to accept this request
14 BufferedReader getReader () returns the decoded request body
15 String getRemoteAddr () returns the IP address of the client that sent this request
16 String getRemoteHost () returns the hostname of the client that sent this request
17 void setAttribute (String key,Object obj) sets the property value of the property
18 String getRealPath (String path) returns the real path of a virtual path
[color=crimson]
2.response object
The response object contains information about responding to customer requests, but it is rarely used directly in JSP. It is an instance of the HttpServletResponse class.
1 String getCharacterEncoding () returns the character encoding used for the response
2 ServletOutputStream getOutputStream () returns a binary output stream of the response
3 PrintWriter getWriter () returns an object that can output characters to the client
4 void setContentLength (int len) sets the response header length
5 void setContentType (String type) sets the MIME type of the response
6 sendRedirect (java.lang.String location) redirect the client's request
3.session object
The session object refers to a session between the client and the server, starting with a WebApplication from the client to the server until the client is disconnected from the server. It is an instance of the HttpSession class.
1 long getCreationTime () returns the SESSION creation time
2 public String getId () returns the unique ID number that the JSP engine gave it when SESSION was created.
3 long getLastAccessedTime () returns the time of the last request from the client in this SESSION
4 int getMaxInactiveInterval () returns the interval between two requests. How long is this SESSION cancelled (ms)
5 String [] getValueNames () returns an array of all available attributes in this SESSION
6 void invalidate () cancels SESSION, making SESSION unavailable
7 boolean isNew () returns a SESSION created by the server, and whether the client has joined
8 void removeValue (String name) deletes the attribute specified in the SESSION
9 void setMaxInactiveInterval () sets how long the interval between two requests this SESSION is cancelled (ms)
4.out object
The out object is an instance of the JspWriter class and is a common object for outputting content to the client.
1 void clear () clears the contents of the buffer
2 void clearBuffer () clears the current contents of the buffer
3 void flush () emptying flow
4 int getBufferSize () returns the size of the buffer in bytes, 0 if no buffer is set
5 int getRemaining () returns how much buffer is left available
6 boolean isAutoFlush () whether to empty automatically or throw an exception when the return buffer is full
7 void close () closes the output stream
5.page object
The page object points to the current JSP page itself, a bit like the this pointer in the class. It is an instance of the java.lang.Object class.
1 class getClass returns the class of this Object
2 int hashCode () returns the hash code of this Object
3 boolean equals (Object obj) determines whether this Object is equal to the specified Object object
4 void copy (Object obj) copies this Object to the specified Object object
5 Object clone () Clone this Object object
6 String toString () converts this Object object to an object of the String class
7 void notify () wakes up a waiting thread
8 void notifyAll () wakes up all waiting threads
9 void wait (int timeout) causes a thread to wait until the timeout ends or wakes up
10 void wait () makes a thread wait until it is woken up
11 void enterMonitor () locks Object
12 void exitMonitor () unlock Object
6.application object
Application object realizes the sharing of data among users and can store global variables. It starts with the startup of the server until the server is shut down, during which time the object will always exist, so that the same property of this object can be manipulated in the front and back connections of users or in connections between different users; the operation of this object property anywhere will affect the access of other users. The startup and shutdown of the server determines the life of the application object. It is an instance of the ServletContext class.
1 Object getAttribute (String name) returns the attribute value of the given name
2 Enumeration getAttributeNames () returns an enumeration of all available property names
3 void setAttribute (String name,Object obj) sets the attribute value of the attribute
4 void removeAttribute (String name) deletes an attribute and its attribute value
5 String getServerInfo () returns the JSP (SERVLET) engine name and version number
6 String getRealPath (String path) returns the real path of a virtual path
7 ServletContext getContext (String uripath) returns the application object of the specified WebApplication
8 int getMajorVersion () returns the maximum version number of the Servlet API supported by the server
9 int getMinorVersion () returns the maximum version number of the Servlet API supported by the server
10 String getMimeType (String file) returns the MIME type of the specified file
11 URL getResource (String path) returns the URL path of the specified resources (files and directories)
12 InputStream getResourceAsStream (String path) returns the input stream of the specified resource
13 RequestDispatcher getRequestDispatcher (String uripath) returns the RequestDispatcher object of the specified resource
14 Servlet getServlet (String name) returns the Servlet of the specified name
15 Enumeration getServlets () returns an enumeration of all Servlet
16 Enumeration getServletNames () returns an enumeration of all Servlet names
17 void log (String msg) writes the specified message to the log file of Servlet
18 void log (Exception exception,String msg) writes the stack trace and error message of the specified exception to the log file of Servlet
19 void log (String msg,Throwable throwable) writes the stack trace and the description of the Throwable exception given to the log file of Servlet
7.exception object
The exception object is an exception object that is generated when an exception occurs while a page is running. If a JSP page wants to apply this object, it must set isErrorPage to true, otherwise it cannot be compiled. He's actually the object of java.lang.Throwable.
1 String getMessage () returns a message describing the exception
2 String toString () returns a short description message about the exception
3 void printStackTrace () displays the exception and its stack trace
4 Throwable FillInStackTrace () overrides the execution stack trace of the exception
five
8.pageContext object
PageContext object provides access to all the objects and namespaces in the JSP page, that is to say, he can access the SESSION where this page is located, or he can take an attribute value of the application where this page is located, which is equivalent to the aggregator of all the functions in the page, and its class name is also called pageContext.
1 JspWriter getOut () returns the JspWriter stream (out) used by the current client response
2 HttpSession getSession () returns the HttpSession object (session) in the current page
3 Object getPage () returns the Object object (page) of the current page
4 ServletRequest getRequest () returns the ServletRequest object (request) of the current page
5 ServletResponse getResponse () returns the ServletResponse object (response) of the current page
6 Exception getException () returns the Exception object (exception) of the current page
7 ServletConfig getServletConfig () returns the ServletConfig object (config) of the current page
8 ServletContext getServletContext () returns the ServletContext object (application) of the current page
9 void setAttribute (String name,Object attribute) sets properties and attribute values
10 void setAttribute (String name,Object obj,int scope) sets properties and attribute values within a specified range
11 public Object getAttribute (String name) takes the value of the attribute
12 Object getAttribute (String name,int scope) takes the value of the attribute within the specified range
13 public Object findAttribute (String name) looks for a property and returns the property value or NULL
14 void removeAttribute (String name) Delete an attribute
15 void removeAttribute (String name,int scope) deletes an attribute in the specified range
16 int getAttributeScope (String name) returns the scope of an attribute
17 Enumeration getAttributeNamesInScope (int scope) returns the enumeration of available attribute names within the specified range
18 void release () releases the resources occupied by pageContext
19 void forward (String relativeUrlPath) redirects the current page to another page
20 void include (String relativeUrlPath) contains another file in the current location
9.config object
The config object is used by the JSP engine to pass information to a Servlet when initializing it, including the parameters to be used for Servlet initialization (composed of attribute names and attribute values) and information about the server (by passing a ServletContext object).
1 ServletContext getServletContext () returns a ServletContext object containing server-related information
2 String getInitParameter (String name) returns the value of the initialization parameter
3 Enumeration getInitParameterNames () returns an enumeration of all parameters required for Servlet initialization
Thank you for reading this article carefully. I hope the article "what are the built-in object methods in JSP" shared by the editor will be helpful to you? at the same time, I also hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!
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.