JSP nine built-in objects

 

Thanks http://bye.javaeye.com/blog/202640
1.request Object 


Request message is encapsulated in the client request object, through which to understand the needs of customers, then responds. It is an instance of class HttpServletRequest. 


DESCRIPTION Method No. 

1 object getAttribute (String name) Returns the specified attribute value of the attribute 

2 Enumeration getAttributeNames () returns an enumeration of all available attribute names 

3 String getCharacterEncoding () Returns character encoding 

4 int getContentLength () returns the length of the body (to request the number of bytes) 

. 5 the getContentType String () to obtain the MIME type of the request body 

6 ServletInputStream getInputStream () request body obtained binary stream line 

7 String getParameter (String name) returns the specified parameter name parameter value 

8 Enumeration getParameterNames () returns the available parameters enumeration name 

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

10 String getProtocol () returns the requested protocol type and version number with 

11 String getScheme () returns the program name with the request, such as: http.https and ftp, etc. 

12 String getServerName () returns the host name of the server to accept the request of

13 int getServerPort () Returns the server accepts port number of the request used 

14 BufferedReader getReader () Returns decoded the request body 

15 String getRemoteAddr () Returns the client sends this request client IP address 

16 String getRemoteHost () Returns sent this request client host name 

17 void setAttribute (String key, Object obj) set the property attribute value 

18 String getRealPath (String path) returns true path of a virtual path 

2.response target 


response contains information about the object in response to client requests, but JSP is rarely used directly on it. It is an instance of class HttpServletResponse. 


DESCRIPTION Method No. 

1 String getCharacterEncoding () returns a response with what character encoding 

2 ServletOutputStream getOutputStream () returns a response to a binary output stream 

3 PrintWriter getWriter () can return to a target client characters output 

4 void setContentLength (int len ) to set the response header length 

5 void setContentType (String type) is provided in response MIME type 

6 sendRedirect (java.lang.String location) redirecting client requests 

 


3.session objects


session object refers to a conversation with the server to the client, the client from a server connected to the WebApplication start until the client disconnects from the server date. It is an instance of HttpSession class. 


No. Method Description 

1 long getCreationTime () Returns SESSION Created 

2 public String getId () Returns the unique ID number when SESSION create a JSP engine for its set of 

3 long getLastAccessedTime () Returns SESSION in client recently a request time 

4 int getMaxInactiveInterval () returns the two long interval this SESSION request is canceled (MS) 

. 5 String [] getValueNames () returns an array of all this SESSION attributes available 

6 void invalidate () cancel SESSION, so SESSION unavailable 

7 boolean isNew () returns whether a SESSION, client server created has joined 

8 void removeValue (String name) delete the specified attribute SESSION 

9 void setMaxInactiveInterval () twice to set how often this request was canceled SESSION (MS) 

4.out objects 


out JspWriter objects are instances of the class, is commonly outputting content to the client object 


No. method Description 

1 void clear () to clear the contents of the buffer

2 void clearBuffer () to clear the current contents of the buffer 

3 void flush () Flush the stream 

4 int getBufferSize () returns the size of the number of bytes in the buffer, as compared with no buffer 0 

. 5 getRemaining int () return buffer further the remaining number of available 

time 6 boolean isAutoFlush () returns the buffer is full, empty or is automatically thrown 

7 void close () closes the output stream 


5.page target 


page object is a pointer to the current JSP page itself, a bit like the this pointer class, it is an instance of the class java.lang.Object 


No. method Description 

1 class getClass Object returns the class 

2 int hashCode () returns the hash code Object 

3 boolean equals (Object obj) determines whether this Object specified Object is equal to 

4 void copy (Object obj) the Related Object copied to the specified object in the Object 

5 Object clone () clone of this Object object 

6 String toString () Object to convert this Object object to a String class 

7 void notify () wake up threads waiting to 

8 void notifyAll () wakes up all waiting threads 

9 void wait (int timeout) so that a thread is waiting until the end of the timeout or wake

10 void wait () makes a thread is waiting until it is awakened 

11 void enterMonitor () for locking Object 

12 void exitMonitor () Object to unlock 



6.application target 


application object implements the sharing of data among users, global variables can be stored. It begins to start the server until the server is shut down in the meantime, the object will always exist; before and after such connection or a user connection between different users in the same attribute of this object can be operated; anywhere this operation object properties, will affect other users of this access. Server startup and shutdown determine the life application object. It is an instance of class ServletContext. 


Method No. Description 

1 Object getAttribute (String name) Returns the value of the attribute to the naming 

2 Enumeration getAttributeNames () returns an enumeration of all available attribute names 

3 void setAttribute (String name, Object obj) set attribute property value 

4 void removeAttribute (String name) deletes a property and property value 

5 String getServerInfo () returns the JSP (SERVLET) engine name and version number 

6 String getRealPath (String path) returns the path of a true virtual path 

7 ServletContext getContext (String uripath) returns WebApplication of application objects

8 int getMajorVersion () Returns the server supports Servlet API is the largest version number 

9 int getMinorVersion () maximum version number returned server supports Servlet API's 

10 String getMimeType (String file) Returns the MIME type of the specified file 

11 URL getResource (String path) returns resources (files and directories) URL path of 

return specified resource 12 InputStream getResourceAsStream (String path) input stream 

13 RequestDispatcher getRequestDispatcher (String uripath) returns the specified resource RequestDispatcher object 

14 Servlet getServlet (String name) returns the name of the Servlet 

15 enumeration getServlets () returns an enumeration of all Servlet 

16 enumeration getServletNames () returns an enumeration of all Servlet name 

17 void log (String msg) to write messages to the specified Servlet log file 

18 void log (Exception exception, String msg) to specify exception stack trace and error messages are written to the log file Servlet 

19 void log (String msg, Throwable throwable) and the stack trace Throwable description given abnormality log file information writing Servlet

7.exception target 


exception object is an exception object, when a page exception occurs during operation, it creates the object. If a JSP page you want to apply for this object, it must take isErrorPage set to true, otherwise it is impossible to compile. Object he is actually java.lang.Throwable 


No. Method Description 

1 String getMessage () returns a message describing the exception 

2 String toString () Returns a short description information about the exception of 

3 void printStackTrace () and displayed abnormal stack trace 

4 Throwable FillInStackTrace () rewrite execution exception stack trace 



8.pageContext objects 


pageContext object provides access to all of the objects and the space within the JSP page name, that he has access to SESSION page where you can withdraw this page is located a property value of the application, he is equivalent to a master page all the features, it's the name of this class, also known as pageContext. 


No. Method Description 

1 JspWriter getOut () Returns the current client in response JspWriter stream (out) to be used 

2 HttpSession getSession () Returns HttpSession object (session) the current page 

3 Object getPage () Returns Object object (page) of the current page 

4 ServletRequest getRequest () returns the ServletRequest object of the current page (request)

5 ServletResponse getResponse () Returns the current ServletResponse objects (response) Page 

6 Exception getException () Returns the current Exception object (Exception) page 

7 ServletConfig getServletConfig () Returns ServletConfig object (config) this page of 

8 ServletContext getServletContext () Returns this page the ServletContext object (file application) 

. 9 void the setAttribute (String name, Object attribute) disposed attributes and attribute values 

10 void setAttribute (String name, Object obj, int scope) disposed attributes and attribute values within the specified range 

11 public Object getAttribute (String name ) value is taken attribute 

12 Object getAttribute (String name, int scope) takes a value attribute within the specified range 

13 public Object findAttribute (String name) to find a property that returns from the attribute value or a NULL 

14 void removeAttribute (String name) delete a properties 

15 void removeAttribute (String name, int scope) delete a property in the specified range

16 int getAttributeScope (String name) Returns a property of the scope 

17 Enumeration getAttributeNamesInScope (int scope) Returns the specified range of available property name enumeration 

18 void release () to release the resources occupied pageContext 

19 void forward (String relativeUrlPath) so that the current redirecting to another page page 

20 void include (String relativeUrlPath) further comprises a file in the current position 


9.config the object 


when the object is at a config initialization Servlet, JSP engine information transmitted to it, this information is initialized to include Servlet parameters used (by property name and attribute value), and information about the server (by passing a ServletContext object) 


No. method Description 

1 ServletContext getServletContext () returns the ServletContext object contains the server-related information 

2 String getInitParameter (String name) returns the initialization parameter value 

3 enumeration getInitParameterNames () returns enum Servlet initialize all required parameters

 

Published 18 original articles · won praise 16 · views 390 000 +

Guess you like

Origin blog.csdn.net/f_zongjian/article/details/5696232