Note:
1. Simplified JSP page development,
2. The implicit object name is a reserved word of JAVA,
3. Implicit objects do not need to be instantiated.
The dynamic content of web pages is accessed through implicit objects. JSP implicit objects are a group of classes loaded by web containers. Let's take a look at one of my articles. Details:
① Out-javax. servlet. jsp. jspWriter
The out object is used to output the result to the webpage.
Method:
1. void clear ();
Clears the content of the output buffer but does not output it to the client.
2. void clearBuffer ();
Clear the content of the output buffer and output it to the client.
3. void close ();
Close the output stream and clear all content.
4. void flush ();
Output Data in the buffer.
5. int getBufferSize ();
Obtains the current buffer size in kb.
6. int getRemaining ();
Obtains the unoccupied space in the buffer in kb.
7. boolean isAutoFlush ();
Whether to automatically refresh the buffer.
8. void newLine ();
Output A line feed character.
9. void print (boolean B );
Void print (char c );
Void print (char [] s );
Void print (double d );
Void print (float f );
Void print (int I );
Void print (long l );
Void print (Object obj );
Void print (String s );
Outputs Data of the specified type to the Http stream without line breaks.
10. void println (boolean B );
Void println (char c );
Void println (char [] s );
Void println (double d );
Void println (float f );
Void println (int I );
Void println (long l );
Void println (Object obj );
Void println (String s );
Output data of the specified type to the Http stream and a line break.
11. Appendable append (char c );
Appendable append (CharSequence cxq, int start, int end );
Appendable append (CharSequence cxq );
Add a character or an object that implements the CharSequence interface to the end of the output stream.
Member:
Int DEFAULT_BUFFER = 0-default buffer size
Int NO_BUFFER =-1-whether the writer is in the buffer output status
Int UNBOUNDED_BUFFER =-2-whether to limit the buffer size
② Request-javax. servlet. http. HttpServletRequest
The request object contains information about all requests, such as the request source, header, cookies, and request-related parameter values.
Method:
1. Object getAttribute (String name );
Returns the property value specified by name. If the property does not exist, null is returned.
2. Enumeration getAttributeNames ();
Returns a set of all attribute names of the request object.
3. String getAuthType ();
Returns the name of the authentication method used to protect the servlet. If not, null is returned.
4. String getCharacterEncoding ();
The character encoding method in the return request, which can be set in the response object.
5. int getContentLength ();
Returns the length of the Request BODY. If the length cannot be determined,-1 is returned. You can set it in response.
6. String getContentType ();
Return the content type defined in response.
7. String getContentPath ();
The path of the returned request.
8. Cookie [] getCookies ();
Returns an array of all cookies on the client.
9. Enumeration getHeaderNames ();
Returns a set of names of all HTTP headers.
10. Enumeration getHeaders (String name );
Returns a set of all values of the specified HTTP header.
11. String getHeader (String name );
Returns the HTTP header of the specified name.
12. long getDateHeader (String name );
Returns the information of the Data-Type HTTP header with the specified name.
13. int getIntHeader (String name );
Returns the Int Type HTTP header of the specified name.
14. ServletInputStream getInputStream ();
Returns the input stream of the request.
15. Locale getLocale ();
Return the Locale object of the current page, which can be set in response.
16. Enumeration getLocales ();
Returns the set of all Locale objects in the request.
17. String getLocalName ();
Obtain the server host name that responds to the request.
18. String getLocalAddr ();
Obtain the server address that responds to the request.
19. int getLocalPort ();
Obtain the server port in response to the request
20. String getMethod ();
Obtain the methods (GET and POST) that the client sends to the server ).
21. String getParameter (String name );
Obtain the parameter value sent from the client to the server.
22. Map getParameterMap ();
This method returns a Map object containing all parameters in the request.
23. Enumeration getParameterNames ();
Returns the set of all parameters in the request.
24. String [] getParameterValues (String name );
Obtain all values of the specified parameter in the request.
25. String getQueryString ();
Returns the parameter string passed by the get method. This method does not parse individual parameters.
26. String getPathInfo ();
Retrieve the additional information in the request between ServletPath and QueryString.
27. String getPathTranslated ();
Returns the actual path of the path information obtained using the getPathInfo () method.
28. String getProtocol ();
The protocol used by the request. It can be HTTP1.1 or HTTP1.0.
29. BufferedReader getReader ();
Returns the Reader object corresponding to the input stream of the request. This method and the getInputStream () method can only be called on one page.
30. String getRemoteAddr ();
Obtain the IP address of the client sending the request.
31. String getRemoteHost ();
Obtain the client host name that sends the request
32. String getRemoteUser ();
Returns the user name verified by the client. If the user name is not verified, null is returned.
33. int getRemotePort ();
Returns the host port of the client sending the request.
34. String getRealPath (String path );
Returns the physical path of the given virtual path.
35. RequestDispatcher getRequestDispatcher (String path );
Generate a resource based on the given path to process the adapter object.
36. String getRequestedSessionId ();
The identifier of the Request session.
37. String RequestURI ();
Returns the client address that sends the request, but does not include the request parameter string.
38. StringBuffer getRequestURI ();
Returns the server address of the Response Request.
39. String getScheme ();
Obtain the protocol name. The default value is HTTP.
40. String getServerName ();
The name of the server that responds to the request.
41. String getServletPath ();
Obtain the path of the script file requested by the client.
42. int getServerPort ();
Obtain the server-side host port number that responds to the request.
43. void removeAttribute (String name );
Delete the attribute of the specified name in the attribute list.
44. void setAttribute (String name, Object value );
Add/delete a specified property in the property list.
45. void setCharacterEncoding (String name );
Set the character encoding format of the request.
46. HttpSession getSession ();
HttpSession getSession (boolean create );
Obtain the session. If create is true, create a session without a session.
47. boolean isRequestedSessionIdFromCookie ();
Check whether the request session ID is passed in through cookies.
48. boolean isRequestedSessionIdFromURL ();
Check whether the request session ID is passed in through the URL.
49. boolean isRequestedSessionIdValid ();
Check whether the request session ID is still valid.
50. boolean isSecure ();
Check whether the request uses a secure link, such as HTTPS.
51. boolean isUserInRole (String role );
Check whether the verified user is in the role specified by role.
52. Principal getUserPrincipal ();
Returns a java. security. Principal object containing the user's login name.
Member:
String BASIC_AUTH = "BASIC "-
String CLIENT_CERT_AUTH = "CLIENT_CERT "-
String DIGEST_AUTH = "DIGEST "-
String FORM_AUTH = "FORM "-
③ Response-javax. servlet. http. HttpServletResponse
The response object mainly transmits the results processed by the JSP Container Back to the client.
Method:
1. void addCookie (Cookie cookie );
Add a Cookie object to save client information.
2. void addDateHeader (String name, long value );
Add an HTTP header of the date type to overwrite the HTTP header of the same name.
3. void addHeader (String name, String value );
Add an HTTP header to overwrite the old HTTP header with the same name.
4. void addIntHeader (String name, int value );
Add an integer HTTP header to overwrite the old HTTP header with the same name.
5. boolean containsHeader (String name );
Determines whether the specified HTTP header exists.
6. String encodeRedirectURL (String url );
Encode the URL used by the sendRedirect () method.
7. String encodeURL (String url );
Encode the URL and return the URL containing the session ID.
8. void flushBuffer ();
Forces the content of the current buffer to be sent to the client.
9. int getBufferSize ();
Obtain the buffer size in kb.
10. String getCharacterEncoding ();
Obtains the character encoding format of the response.
11. String getContentType ();
Obtain the response type.
12. Locale getLocale ();
Obtain the response Locale object.
13. ServletOutputStream getOutputStream ();
Return the output stream object of the client.
14. PrintWriter getWriter ();
Gets the writer object corresponding to the output stream.
15. boolean isCommitted ();
Determine whether the server has output data to the client.
16. void reset ();
Clears all content in the buffer.
17. void resetBuffer ();
Buffer, but the HTTP header and status information are retained.
18. void sendError (int xc, String msg );
Void sendError (int xc );
Sending error, including status code and error message.
19. void sendRedirect (String locationg );
Send the response to another location for processing.
20. void setBufferSize (int size );
Set the buffer size in kb.
21. void setCharacterEncoding (String charset );
Set the character encoding format used by the response.
22. void setContentLength (int length );
Set the length of the response BODY.
23. void setContentType (String type );
Set the response type.
24. void setDateHeader (String name, long value );
Set the value of the Data-Type HTTP header with the specified name.
25. void setHeader (String name, String value );
Set the HTTP header value of the specified name.
26. void setIntHeader (String name, int value );
Set the int Type HTTP header value of the specified name.
27. void setStatus (int xc );
Set the response status code. The new value overwrites the current value.
Member (HTTP status code ):
Int SC _CONTINUE = 100 int SC _SWITCHING_PROTOCOLS = 101
Int SC _ OK = 200 int SC _NON_AUTHORITATIVE_INFORMATION = 203
Int SC _access Ted = 202 int SC _CREATED = 201
Int SC _NO_CONTENT = 204 int SC _RESET_CONTENT = 205
Int SC _PARTIAL_CONTENT = 206 int SC _MULTIPLE_CHOICES = 300
Int SC _MOVED_PERMANENTLY = 301 int SC _MOVED_TEMPORARILY = 302
Int SC _FOUND = 302 int SC _SEE_OTHER = 303
Int SC _NOT_MODIFIED = 304 int SC _USE_PROXY = 305
Int SC _temporary_redirect= 307 int SC _BAD_REQUEST = 400
Int SC _UNAUTHORIZED = 401 int SC _PAYMENT_REQUIRED = 402
Int SC _FORBIDDEN = 403 int SC _NOT_FOUND = 404
Int SC _METHOD_NOT_ALLOWED = 405 int SC _NOT_ACCEPTABLE = 406
Int SC _proxy_authentication_required= 407 int SC _REQUEST_TIMEOUT = 408
Int SC _CONFLICT = 409 int SC _GONE = 410
Int SC _LENGTH_REQUIRED = 411 int SC _PRECONDITION_FAILED = 412
Int SC _REQUEST_ENTITY_TOO_LARGE = 413 int SC _REQUEST_URI_TOO_LONG = 414
Int SC _UNSUPPORTED_MEDIA_TYPE = 415 int SC _REQUESTED_RANGE_NOT_SATISFIABLE = 416
Int SC _EXPECTATION_FAILED = 417 int SC _INTERNAL_SERVER_ERROR = 500
Int SC _NOT_IMPLEMENTED = 501 int SC _BAD_GATEWAY = 502
Int SC _SERVICE_UNAVAILABLE = 503 int SC _GATEWAY_TIMEOUT = 504
Int SC _HTTP_VERSION_NOT_SUPPORTED = 505
④ Session-javax. servlet. http. HttpSession
Session Object indicates the session Status of individual users, which is used to identify each user.
Method:
1. Object getAttribute (String name );
Obtains the session attribute value associated with the specified name.
2. Enumeration getAttributeNames ();
Obtains the set of all attributes in a session.
3. long getCreationTime ();
Returns the creation time of the session. The minimum unit is 1‰ seconds.
4. String getId ();
Obtains the session ID.
5. long getLastAccessedTime ();
Returns the last access time of the client associated with the current session, measured from, in milliseconds.
6. int getMaxInactiveInterval (int interval );
Total time returned, in seconds, indicates the effective time of the session (the time when the session is not active ). -1 indicates that it never expires.
7. ServletContext getServletContext ();
Returns an instance of the ServletContext object corresponding to the JSP page.
8. HttpSessionContext getSessionContext ();
9. Object getValue (String name );
It is not recommended to obtain the session variable value of the specified name.
10. String [] getValueNames ();
It is not recommended to obtain the set of names of all session variables.
11. void invalidate ();
Destroy this session object.
12. boolean isNew ();
Checks whether a session is generated by the server, but is not used by the client.
13. void pubValue (String name, Object value );
It is not recommended to add a session variable.
14. void removeValue (String name );
It is not recommended to remove the value of a session variable.
15. void setAttribute (String name, String value );
Sets the session attribute value of the specified name.
16. void setMaxInactiveInterval (int interval );
Set the session validity period.
17. void removeAttribute (String name );
Removes the session attribute of the specified name.
⑤ PageContext-javax. servlet. jsp. PageContext
The pageContext object stores information about the JSP page, such as attributes and built-in objects.
Method:
1. void setAttribute (String name, Object value, int scope );
Void setAttribute (String name, Object value );
Set attributes within the specified sharing range.
2. Object getAttribute (String name, int scope );
Object getAttribute (String name );
Obtains the attribute value named name in the specified shared range.
3. Object findAttribute (String name );
Search for named properties by PAGE, request, session, and application sharing range.
4. void removeAttribute (String name, int scope );
Void removeAttribute (String name );
Removes the attribute of the specified name and shared range.
5. void forward (String url );
Navigate to the specified URL.
6. Enumeration getAttributeNamesScope (int scope );
Obtains a set of all attribute names within a specified shared range.
7. int getAttributeScope (String name );
Obtains the shared range of a specified attribute.
8. ErrorData getErrorDate ();
Get the errorData object of the page.
9. Exception getException ();
Get the exception object of the page.
10. ExpressionEvaluator getExpressionEvaluator ();
Obtain the expressionEvaluator object of the page.
11. JspWriter getOut ();
Obtain the out object of the page.
12. Object getPage ();
Obtain the page Object of the page.
13. ServletRequest getRequest ();
Obtain the request object of the page.
14. ServletResponse getResponse ();
Obtain the response object of the page.
15. ServletConfig getConfig ();
Get the config object of the page.
16. ServletContext getServletContext ();
Obtain the servletContext object of the page.
17. HttpSession getSession ();
Obtain the session object of the page.
18. VariableResolver getVariableResolver ();
Obtain the variableResolver object of the page.
19. void include (String url, boolean flush );
Void include (String url );
Contains other resources and specifies whether to automatically refresh.
20. void release ();
Reset the internal status of pageContext to release all internal references.
21. void initialize (Servlet servlet, ServletRequest request, ServletResponse response,
String errorPageURL, boolean needSession, int bufferSize, boolean autoFlush );
Initialize the uninitialized pageContext object.
22. BodyContext pushBody ();
BodyContext pushBody (Writer writer );
Save the current out object and update the out object in the page range of pageContext.
23. JspWrite popBody ();
Retrieve the out object saved by the pushBody () method.
24. void handlePageException (Exception e );
Void handlePageException (Thrwoable t );
Member:
Int PAGE_SCOPE = 1-page sharing range
Int REQUEST_SCOPE = 2-request sharing range
Int SESSION_SCOPE = 3-session sharing range
Int APPLICATION_SCOPE = 4-application sharing range
String PAGE = "javax. servlet. jsp. jspPage"
String PAGECONTEXT = "javax. servlet. jsp. jspPageContext"
String REQUEST = "javax. servlet. jsp. jspRequest"
String RESPONSE = "javax. servlet. jsp. jspResponse"
String CONFIG = "javax. servlet. jsp. jspConfig"
String SESSION = "javax. servlet. jsp. jspSession"
String OUT = "javax. servlet. jsp. jspOut"
String APPLICATION = "javax. servlet. jsp. jspApplication"
String EXCEPTION = "javax. servlet. jsp. jspException"
⑥ Application-javax. servlet. ServletContext
The main function of application is to get or change Servlet settings.
Method:
1. Object getAttribute (String name );
Returns the application attribute specified by name.
2. Enumeration getAttributes ();
Returns all application attributes.
3. ServletContext getContext (String uripath );
Obtains the ServletContext object of the current application.
4. String getInitParameter (String name );
Returns the initial value of the application attribute specified by name.
5. Enumeration getInitParameters ();
Returns the set of initial values of all application attributes.
6. int getMajorVersion ();
Returns the version number of the servlet API supported by the Servlet container.
7. String getMimeType (String file );
Returns the type of the specified file. returns null for the unknown type. It is generally "text/html" and "image/gif ".
8. int getMinorVersion ();
Return the minor version number of the servlet API supported by the Servlet container.
9. String getRealPath (String path );
Returns the physical path corresponding to the given virtual path.
10. RequestDispatcher getNamedDispatcher (String name );
Returns an instance of the RequestDispatcher object for the Servlet object with the specified name.
11. RequestDispatcher getRequestDispatcher (String path );
Returns an instance of a RequestDispatcher object.
12. URL getResource (String path );
Returns a URL object instance corresponding to the specified resource path. The parameter must start.
13. InputStream getResourceAsStream (String path );
Returns an InputStream object instance of a resource at the specified position of the path.
14. Set getResourcePaths (String path );
Returns the set of all resource paths stored in the web-app.
15. String getServerInfo ();
Obtain the application server version.
16. Servlet getServlet (String name );
Search for the servlet with the specified name in ServletContext.
17. Enumeration getServlets ();
Returns the set of all servlets in the ServletContext.
18. String getServletContextName ();
Returns the name of the web application.
19. Enumeration getServletContextNames ();
Returns the name set of all servlets in the ServletContext.
20. void log (Exception ex, String msg );
Void log (String msg, Throwable t );
Void log (String msg );
Write the specified information to the servlet log file.
21. void removeAttribute (String name );
Removes the application attribute of the specified name.
22. void setAttribute (String name, Object value );
Set the value of the specified application attribute.
7. config-javax. servlet. ServletConfig
The config object is used to store the initial Servlet data structure.
Method:
1. String getInitParameter (String name );
Returns the value of the prompt parameter named name.
2. Enumeration getInitParameters ();
Returns the names of all the prompt parameters in the JSP.
3. ServletContext getContext ();
The servlet context of the performer.
4. String getServletName ();
The name of the servlet.
Except exception-java. lang. Throwable
Error object. The exception object can be used on this page only after isErrorPage = "true" is specified in the page command of the JSP page.
Method:
1. Throwable fillInStackTrace ();
Record the current stack information to the exception object.
2. String getLocalizedMessage ();
Obtain the error message of the local language.
3. String getMessage ()
Get error message.
4. StackTrackElement [] getStackTrace ();
Return the call stack track information recorded in the object.
5. Throwable initCause (Throwable cause );
Nest another exception object into the current exception object.
6. Throwable getCause ();
Retrieve exceptions nested in the current exception object.
7. void printStackTrace ();
Void printStackTrace (printStream s );
Void printStackTrace (printWriter s );
Print Throwable and its call stack trace information.
8. void setStackTrace (StackTraceElement [] stackTrace)
Sets the call stack trace information of an object.
Dynamic page-javax. servlet. jsp. HttpJspPage
The page object represents the JSP object itself, or the compiled servlet object,
You can use (javax. servlet. jsp. HttpJspPage) page to obtain its methods and attributes.
By Peng Yancheng