JSP built-in objects

Source: Internet
Author: User
Tags flush header session id string stack trace version variable throwable
Js| Object

①out-javax.servlet.jsp.jspwriter
The Out object is used to output the results to the Web page.

Method:
1. void clear ();
Clears the contents of the output buffer, but does not output to the client.

2. void Clearbuffer ();
Clears the contents of the output buffer and outputs it to the client.

3. void Close ();
Closes the output stream and clears all content.

4. void Flush ();
The data inside the output buffer.

5. int getbuffersize ();
Gets the current buffer size in kilobytes.

6. int getremaining ();
Gets the amount of space that is not occupied in a buffer in kilobytes.

7. Boolean Isautoflush ();
Whether the buffer is automatically refreshed.

8. void newline ();
Output a newline 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); The
   outputs the data of the specified type to the HTTP stream without wrapping.

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);
Outputs the specified type of data to the HTTP stream and outputs a newline character.

Appendable append (char c);
Appendable Append (charsequence cxq, int start, int end);
Appendable Append (charsequence cxq);
Adds a character or an object that implements the Charsequence interface to the back of the output stream.

Members:
int default_buffer = 0-Default buffer size
int no_buffer = -1-writer is in buffered output state
int unbounded_buffer =-2-Limit buffer size


②request-javax.servlet.http.httpservletrequest
The Request object contains all the requested information, such as the source of the request, headers, cookies, and request-related parameter values.

Method:
1. Object getattribute (String name);
Returns the value of the property specified by name, which returns null if the property does not exist.

2. Enumeration Getattributenames ();
Returns a collection of all the property names for the request object.

3. String Getauthtype ();
Returns the name of the authentication method used to protect the servlet and returns NULL when unprotected.

4. String getcharacterencoding ();
Returns the character encoding method in the request, which can be set in the response object.

5. int getcontentlength ();
Returns the length of the requested body, not 1 when the length is not determined. Can be set in response.

6. String getContentType ();
Returns the type of content defined in response.

7. String Getcontentpath ();
Returns the path of the request.

8. cookie[] GetCookies ();
Returns an array of all cookies for the client.

9. Enumeration Getheadernames ();
Returns a collection of the names of all HTTP headers.

Enumeration Getheaders (String name);
Returns a collection of all values for the specified HTTP header.

A. String GetHeader (string name);
Returns information about the HTTP header for the specified name.

Long Getdateheader (String name);
Returns information for the HTTP header of the data type of the specified name.

Getintheader Int (String name);
Returns information for the HTTP header of the type int of the specified name.

ServletInputStream getInputStream ();
Returns the input stream for the request.

Locale GetLocale ();
Returns the locale object for the current page, which can be set in response.

Enumeration Getlocales ();
Returns a collection of all the locale objects in the request.

String Getlocalname ();
Gets the server-side host name of the response request.

A. String getlocaladdr ();
Gets the server-side address of the response request.

Getlocalport Int ();
Get the server-side port that responds to the request

String GetMethod ();
Gets the method (get, POST) that the client sends the request to the server side.

String GetParameter (string name);
Gets the parameter values that the client sends to the server side.

Map Getparametermap ();
This method returns a Map object that contains all the parameters in the request.

Enumeration Getparameternames ();
Returns a collection of all the parameters in the request.

String[] Getparametervalues (String name);
Gets all the values for the specified parameter in the request.

String getquerystring ();
Returns the string of arguments passed by the Get method, which does not break out individual parameters.

A. String getpathinfo ();
Remove additional information between Servletpath and QueryString in the request.

A. String getpathtranslated ();
Returns the actual path of the path information obtained using the GetPathInfo () method.

String Getprotocol ();
Returns the protocol used by the request. It can be HTTP1.1 or HTTP1.0.

BufferedReader Getreader ();
Returns the reader object for the requested input stream, which can only be invoked on one page for a getInputStream () method.

String getremoteaddr ();
Gets the client IP address that issued the request.

String Getremotehost ();
Gets the client host name that issued the request

String Getremoteuser ();
Returns a client-authenticated user name that returns null without validation.

Getremoteport Int ();
Returns the client host port on which the request was made.

Getrealpath string (string path);
Returns the physical path of the given virtual path.

RequestDispatcher getrequestdispatcher (String path);
Generates a resource by the given path to process the adapter object.

A. String Getrequestedsessionid ();
Returns the identity of the requested session.

RequestUri String ();
Returns the client address that issued the request, but does not include the requested parameter string.

StringBuffer Getrequesturi ();
Returns the server-side address of the response request

Getscheme String ();
Gets the protocol name, which defaults to the HTTP protocol.

getServerName String ();
Returns the name of the server that responded to the request.

A. String Getservletpath ();
Gets the file path of the script file requested by the client.

Getserverport Int ();
Gets the server-side host port number in response to the request.

removeattribute void (String name);
Deletes the property of the specified name in the list of properties.

void SetAttribute (String name, Object value);
Adds/deletes the specified property to the list of properties.

setcharacterencoding void (String name);
Sets the character encoding format of the request.

HttpSession getsession ();
HttpSession getsession (Boolean create);
Gets the session, if Create is true, and creates one without a session.

Boolean Isrequestedsessionidfromcookie ();
Check that the requested session ID is passed through a cookie.

Boolean Isrequestedsessionidfromurl ();
Checks whether the requested session ID is passed in by URL.

Boolean isrequestedsessionidvalid ();
Check that the requested session ID is still valid.

Boolean issecure ();
Check whether the request uses a secure link, if HTTPS, and so on.

A Boolean isuserinrole (String role);
Check to see if the user who has passed the validation is in the role specified by roles.

Principal Getuserprincipal ();
Returns a Java.security.Principal object that contains the user login name.

Members:
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 passes the results of the JSP container processing back to the client.

Method:
1. Void Addcookie (cookie cookie);
Add a Cookie object to save the client information.

2. void Adddateheader (String name, Long value);
Adds HTTP header information for a date type, overwriting HTTP header information with the same name.

3. void AddHeader (string name, string value);
Add an HTTP header that overwrites the old HTTP header with the same name.

4. void Addintheader (String name, int value);
Adds an integer HTTP header that overwrites an old HTTP header with the same name.

5. Boolean Containsheader (String name);
Determines whether the specified HTTP header exists.

6. String encoderedirecturl (string url);
Encodes the URL used by the Sendredirect () method.

7. String encodeurl (string url);
Encodes the URL to return the URL that contains the session ID.

8. void Flushbuffer ();
Forces the contents of the current buffer to be sent to the client.

9. int getbuffersize ();
Gets the size of the buffer in kilobytes.

String getcharacterencoding ();
Gets the character encoding format of the response.

A. String getcontenttype ();
Gets the type of the response.

Locale GetLocale ();
Gets the locale object for the response.

Servletoutputstream Getoutputstream ();
Returns the output stream object for the client.

PrintWriter getwriter ();
Gets the writer object that corresponds to the output stream.

Boolean iscommitted ();
Determine if the server side has output data to the client.

void Reset ();
Clears all content in the buffer.

void Resetbuffer ();
All content in buffer, but preserves HTTP headers and state information.

void Senderror (int xc, String msg);
void Senderror (int xc);
Send errors, including status codes and error messages.

(a) void Sendredirect (String locationg);
Send the response to another location for processing.

void setbuffersize (int size);
Sets the size of the buffer in kilobytes.

void Setcharacterencoding (String charset);
Sets the character encoding format used by the response.

void setcontentlength (int length);
Sets the body length of the response.

setContentType void (String type);
Sets the type of response.

void Setdateheader (String name, Long value);
Sets the value of the HTTP header for the data type of the specified name.

SetHeader void (string name, string value);
Sets the value of the HTTP header for the specified name.

Setintheader void (String name, int value);
Sets the value of the HTTP header for the type int of the specified name.

(a) void setstatus (int xc);
Sets the response status code, and the new value overrides the current value.

member (HTTP status code):


int sc_continue = int Sc_switching_protocols = 101


int sc_ok = int sc_non_authoritative_information = 203


int sc_accepted = sc_created int = 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 = 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
The Session object represents the current conversation state of individual users and is used to identify each user.

Method:
1. Object getattribute (String name);
Gets the value of the session property associated with the specified name.

2. Enumeration Getattributenames ();
Gets a collection of all the attributes within the session.

3. Long GetCreationTime ();
Returns the creation time of the session, with a minimum unit of 1 per thousand seconds.

4. String getId ();
Gets the session ID.

5. Long Getlastaccessedtime ();
Returns the last access time for the client associated with the current session, measured in milliseconds from 1970-01-01.

6. int getmaxinactiveinterval (int interval);
Returns the total time, in seconds, that represents the active time of the session (the session inactivity time). -1 is never expired.

7. ServletContext Getservletcontext ();
Returns an instance of the ServletContext object corresponding to the JSP page.

8. Httpsessioncontext Getsessioncontext ();

9. Object GetValue (String name);
Gets the value of the session variable for the specified name and is not recommended for use.

String[] GetValueNames ();
Gets a collection of the names of all session variables and is not recommended for use.

A. void invalidate ();
Destroy this session object.

Boolean isnew ();
Determines whether a session is generated by the server, but is not used by the client.

Pubvalue void (String name, Object value);
Add a session variable that is not recommended for use.

removevalue void (String name);
Removing the value of a session variable is not recommended.

void setattribute (string name, string value);
Sets the value of the session property for the specified name.

void setmaxinactiveinterval (int interval);
Sets the duration of the session.

void RemoveAttribute (String name);
Removes the session property of the specified name.


⑤pagecontext-javax.servlet.jsp.pagecontext
The PageContext object stores information related to this JSP page, such as attributes, built-in objects, and so on.

Method:
1. void setattribute (String name, Object value, int scope);
void SetAttribute (String name, Object value);
Sets the property within the specified shared scope.

2. Object getattribute (String name, int scope);
Object getattribute (String name);
Gets the value of the property within the specified shared range named by name.

3. Object Findattribute (String name);
Searches for named properties by page, request, session, and application sharing scope.

4. void RemoveAttribute (String name, int scope);
void RemoveAttribute (String name);
Removes the property for the specified name and shared scope.

5. Void forward (String URL);
Navigates the page to the specified URL.

6. Enumeration Getattributenamesscope (int scope);
Gets a collection of all the property names within the specified shared scope.

7. int Getattributescope (String name);
Gets the shared scope of the specified property.

8. ErrorData geterrordate ();
Gets the ErrorData object for the page.

9. Exception getexception ();
Gets the exception object for the page.

ExpressionEvaluator Getexpressionevaluator ();
Gets the ExpressionEvaluator object for the page.

JspWriter getout ();
Gets the Out object of the page.

Object GetPage ();
Gets the page object for the sheet.

ServletRequest getrequest ();
Gets the request object for the page.

Servletresponse GetResponse ();
Gets the response object for the page.

ServletConfig GetConfig ();
Gets the config object for the page.

ServletContext Getservletcontext ();
Gets the ServletContext object for the page.

HttpSession getsession ();
Gets the session object for the page.

Variableresolver Getvariableresolver ();
Gets the Variableresolver object for the page.

void include (String URL, boolean flush);
void include (String URL);
Contains additional resources and specifies whether to refresh automatically.

void release ();
Resets the PageContext internal state, releasing all internal references.

void Initialize (servlet servlet, servletrequest request, servletresponse response,
String Errorpageurl, Boolean needsession, int buffersize, Boolean autoflush);
Initializes an uninitialized PageContext object.

Bodycontext Pushbody ();
Bodycontext pushbody (Writer Writer);
Saves the current out object and updates the Out object in page range in PageContext.

Jspwrite Popbody ();
Remove the Out object saved by the Pushbody () method.

void Handlepageexception (Exception e);
void Handlepageexception (Thrwoable t);

Members:
int page_scope = 1-page Share range
int request_scope = 2-Request Shared scope
int session_scope = 3-session sharing scope
int application_scope = 4-Application Sharing scope
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 obtain or change the servlet settings.

Method:
1. Object getattribute (String name);
Returns the Application property specified by name.

2. Enumeration GetAttributes ();
Returns all the application properties.

3. ServletContext getcontext (String uripath);
Gets the ServletContext object for the current application.

4. String Getinitparameter (string name);
Returns the initial value of the application property specified by name.

5. Enumeration Getinitparameters ();
Returns a collection of the initial values for all application properties.

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, and the unknown type returns NULL. Generally "text/html" and "Image/gif".

8. int getminorversion ();
Returns the 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.

RequestDispatcher getnameddispatcher (String name);
Returns an instance of a RequestDispatcher object for the Servlet object of the specified name.

RequestDispatcher getrequestdispatcher (String path);
Returns an instance of a RequestDispatcher object.

A. URL getresource (String path);
Returns an instance of the URL object for the specified resource path, with the argument starting with "/".

InputStream getResourceAsStream (String path);
Returns an instance of the InputStream object for the resource at the location specified by path.

Set getresourcepaths (String path);
Returns a collection of all resource paths stored in Web-app.

String Getserverinfo ();
Gets the application server version information.

Servlet Getservlet (String name);
Retrieves the servlet of the specified name in ServletContext.

Enumeration Getservlets ();
Returns a collection of all the servlet in ServletContext.

A. String getservletcontextname ();
Returns the name of this Web application.

Enumeration Getservletcontextnames ();
Returns a collection of the names of all the servlet in ServletContext.

void log (Exception ex, String msg);
void log (String msg, Throwable t);
void log (String msg);
Writes the specified information to the servlet log file.

void RemoveAttribute (String name);
Removes the application property of the specified name.

void SetAttribute (String name, Object value);
Sets the value of the specified application property.


⑦config-javax.servlet.servletconfig
Config object is used to store the initial data structure of the servlet.

Method:
1. String Getinitparameter (string name);
Returns the value of the push parameter named name.

2. Enumeration Getinitparameters ();
Returns a collection of the names of all the prompting parameters for this JSP.

3. ServletContext GetContext ();
Returns the servlet context of the performer.

4. String getservletname ();
Returns the name of the servlet.


⑧exception-java.lang.throwable
Error object, you can use the exception object on this page only if you specify Iserrorpage= "true" in the page instruction of the JSP page.

Method:
1. Throwable fillinstacktrace ();
Logs the current stack information to the exception object.

2. String getlocalizedmessage ();
Gets the local language family error message.

3. String GetMessage ()
Get the error message.

4. stacktrackelement[] Getstacktrace ();
Returns the call stack track information recorded in the object.

5. Throwable initcause (throwable cause);
Nesting another exception object into the current exception object.

6. Throwable getcause ();
Removes the exception that is nested in the current exception object.

7. void Printstacktrace ();
void Printstacktrace (PrintStream s);
void Printstacktrace (PrintWriter s);
Print out Throwable and its call stack trace information.

8. Void Setstacktrace (stacktraceelement[] stacktrace)
Sets the call stack trace information for an object.


⑨page-javax.servlet.jsp.httpjsppage
The Page object represents the JSP object itself, or represents a compiled Servlet object.
You can use the ((javax.servlet.jsp.HttpJspPage) page) to fetch its methods and properties.







Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.