JSP built-in objects and common methods JSP built-in objects and common methods

JSP built-in objects and common methods

 

JSP nine built-in objects and four scopes:

What is scope

  Let's see the effect first:

  The process is probably like this. When we visit index.jsp, we accumulate the variables in the four scopes of pageContext, request, session, and application respectively. (Of course, first determine whether the variable exists. If the variable does not exist, the variable should be initialized to 1). After the calculation is completed, execute the forward jump from index.jsp to test.jsp. Accumulate again in test.jsp, and then display the four integers.

  From the displayed results, we can intuitively draw the following conclusions:

  Variables in page cannot be passed from index.jsp to test.jsp. As soon as the page jumps, they are gone.

  The variables in the request can span two pages before and after the forward. But they are recalculated whenever the page is refreshed.

  The variables in the session and application have been accumulating, and there is no difference at first. As long as the browser is closed and the browser is restarted again to access this page, the variables in the session will be recalculated.

    The variables in the application keep accumulating, unless you restart tomcat, it will keep getting bigger.

The scope specifies the validity period of the variable

  If the variable is placed in the pageContext, it means that its scope is page, and its effective scope is only in the current jsp page.

  You can use this variable from putting the variable in the pageContext to the end of the jsp page.

  If the variable is placed in the request, it means that its scope is request, and its valid scope is the current request cycle.

  The so-called request cycle refers to the entire process from the initiation of the http request to the end of the server processing and the return of the response. In this process, you may use the forward method to jump to multiple jsp pages, and you can use this variable in these pages.

  If the variable is placed in the session, it means that its scope is session, and its effective scope is the current session.

  The so-called current session refers to the process from when the user opens the browser to when the user closes the browser. This process may contain multiple request responses. That is to say, as long as the user does not close the browser, the server has a way to know that these requests are initiated by one person. The whole process is called a session, and the variables placed in the session can be used in all the current session. used in the request.

  If the variable is placed in the application, it means that its scope is application, and its effective scope is the entire application.

  The whole application refers to the start of the application and the end of the application. We didn't say "from server startup to server shutdown" because a server may deploy multiple applications. Of course, if you shut down the server, all the above applications will be shut down.

  Variables in the application scope have the longest survival time, and they can always be used if they are not manually deleted.

  Unlike the above three, variables in the application can be shared by all users. If user A's operation modifies a variable in the application, user B will get the modified value when accessing it. This will not happen in other scopes, page, request, session are completely isolated, no matter how the modification will not affect other people's data.

Common methods of request

lGet client information

 • The getRequestURL method returns the full URL when the client made the request.

 • The getRequestURI method returns the resource name part of the request line.

 • The getQueryString method returns the parameter portion of the request line.

 • The getRemoteAddr method returns the IP address of the requesting client

 • The getRemoteHost method returns the full hostname of the requesting client

 • getRemotePort method returns the network port number used by the client

 • The getLocalAddr method returns the IP address of the WEB server.

 • getLocalName method returns the host name of the WEB server

 • getMethod to get the client request method

 

response object

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

1 String getCharacterEncoding() returns what character encoding is 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) Set the length of the response header

5 void setContentType(String type) Set the MIME type of the response

6 sendRedirect(java.lang.String location) redirects the client's request

 

session object

The session object refers to a session between the client and the server, starting from a WebApplication where the client connects to the server, until the client disconnects 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 set by the JSP engine for it when the SESSION was created

3 long getLastAccessedTime() Returns the last request time of the client in this SESSION

4 int getMaxInactiveInterval() returns how long the interval between two requests is this SESSION canceled (ms) 

5 String[] getValueNames() returns an array containing all available properties in this SESSION

6 void invalidate() cancels SESSION, making SESSION unavailable

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

8 void removeValue(String name) delete the property specified in SESSION

9 void setMaxInactiveInterval() Set how long between two requests this SESSION is cancelled (ms)

 


jsp action and function
JSP has the following six basic actions:
    jsp:include: import a file when the page is requested;
    jsp:useBean: find or instantiate a JavaBean. ;
    jsp:setProperty: Set the properties of the JavaBean. ;
    jsp:getProperty: output the properties of a JavaBean;
    jsp:forward: forward the request to a new page;
    jsp:plugin: generate OBJECT or EMBED tags for Java plug-ins according to the browser type

JSP nine built-in objects and four scopes:

What is scope

  Let's see the effect first:

  The process is probably like this. When we visit index.jsp, we accumulate the variables in the four scopes of pageContext, request, session, and application respectively. (Of course, first determine whether the variable exists. If the variable does not exist, the variable should be initialized to 1). After the calculation is completed, execute the forward jump from index.jsp to test.jsp. Accumulate again in test.jsp, and then display the four integers.

  From the displayed results, we can intuitively draw the following conclusions:

  Variables in page cannot be passed from index.jsp to test.jsp. As soon as the page jumps, they are gone.

  The variables in the request can span two pages before and after the forward. But they are recalculated whenever the page is refreshed.

  The variables in the session and application have been accumulating, and there is no difference at first. As long as the browser is closed and the browser is restarted again to access this page, the variables in the session will be recalculated.

    The variables in the application keep accumulating, unless you restart tomcat, it will keep getting bigger.

The scope specifies the validity period of the variable

  If the variable is placed in the pageContext, it means that its scope is page, and its effective scope is only in the current jsp page.

  You can use this variable from putting the variable in the pageContext to the end of the jsp page.

  If the variable is placed in the request, it means that its scope is request, and its valid scope is the current request cycle.

  The so-called request cycle refers to the entire process from the initiation of the http request to the end of the server processing and the return of the response. In this process, you may use the forward method to jump to multiple jsp pages, and you can use this variable in these pages.

  If the variable is placed in the session, it means that its scope is session, and its effective scope is the current session.

  The so-called current session refers to the process from when the user opens the browser to when the user closes the browser. This process may contain multiple request responses. That is to say, as long as the user does not close the browser, the server has a way to know that these requests are initiated by one person. The whole process is called a session, and the variables placed in the session can be used in all the current session. used in the request.

  If the variable is placed in the application, it means that its scope is application, and its effective scope is the entire application.

  The whole application refers to the start of the application and the end of the application. We didn't say "from server startup to server shutdown" because a server may deploy multiple applications. Of course, if you shut down the server, all the above applications will be shut down.

  Variables in the application scope have the longest survival time, and they can always be used if they are not manually deleted.

  Unlike the above three, variables in the application can be shared by all users. If user A's operation modifies a variable in the application, user B will get the modified value when accessing it. This will not happen in other scopes, page, request, session are completely isolated, no matter how the modification will not affect other people's data.

Common methods of request

lGet client information

 • The getRequestURL method returns the full URL when the client made the request.

 • The getRequestURI method returns the resource name part of the request line.

 • The getQueryString method returns the parameter portion of the request line.

 • The getRemoteAddr method returns the IP address of the requesting client

 • The getRemoteHost method returns the full hostname of the requesting client

 • getRemotePort method returns the network port number used by the client

 • The getLocalAddr method returns the IP address of the WEB server.

 • getLocalName method returns the host name of the WEB server

 • getMethod to get the client request method

 

response object

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

1 String getCharacterEncoding() returns what character encoding is 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) Set the length of the response header

5 void setContentType(String type) Set the MIME type of the response

6 sendRedirect(java.lang.String location) redirects the client's request

 

session object

The session object refers to a session between the client and the server, starting from a WebApplication where the client connects to the server, until the client disconnects 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 set by the JSP engine for it when the SESSION was created

3 long getLastAccessedTime() Returns the last request time of the client in this SESSION

4 int getMaxInactiveInterval() returns how long the interval between two requests is this SESSION canceled (ms) 

5 String[] getValueNames() returns an array containing all available properties in this SESSION

6 void invalidate() cancels SESSION, making SESSION unavailable

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

8 void removeValue(String name) delete the property specified in SESSION

9 void setMaxInactiveInterval() Set how long between two requests this SESSION is cancelled (ms)

 


jsp action and function
JSP has the following six basic actions:
    jsp:include: import a file when the page is requested;
    jsp:useBean: find or instantiate a JavaBean. ;
    jsp:setProperty: Set the properties of the JavaBean. ;
    jsp:getProperty: output the properties of a JavaBean;
    jsp:forward: forward the request to a new page;
    jsp:plugin: generate OBJECT or EMBED tags for Java plug-ins according to the browser type

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325412907&siteId=291194637