Home  >  Article  >  Java  >  Introduce and explain the functions of the nine built-in objects in JSP

Introduce and explain the functions of the nine built-in objects in JSP

PHPz
PHPzOriginal
2024-01-31 16:03:06975browse

Introduce and explain the functions of the nine built-in objects in JSP

Introduction and functions of the nine built-in objects of JSP

1. request

The request object represents the request sent by the client , including all information sent by the client, such as request parameters, request headers, etc. It is a javax.servlet.http.HttpServletRequest object.

Function:

  • Get request parameters: request.getParameter(String name)
  • Get request header: request.getHeader(String name )
  • Get the request method: request.getMethod()
  • Get the request URI: request.getRequestURI()
  • Get the request URL: request.getRequestURL()
  • Get the request protocol: request.getProtocol()
  • Get the request character encoding: request.getCharacterEncoding()
  • Get the request content type: request.getContentType()
  • Get Request content length: request.getContentLength()
  • Get the requested ServletPath: request.getServletPath()
  • Get the requested ContextPath: request.getContextPath()
  • Get the requested Session: request.getSession()
  • Get the requested Cookies: request.getCookies()
  • Get the requested Locale: request.getLocale()

2. response

The response object represents the server's response to the client, including all data to be sent to the client, such as response headers, response bodies, etc. It is a javax.servlet.http.HttpServletResponse object.

Function:

  • Set the response status code: response.setStatus(int sc)
  • Set the response header: response.setHeader(String name, String value)
  • Set the response character encoding: response.setCharacterEncoding(String charset)
  • Set the response content type: response.setContentType(String contentType)
  • Get the response output Stream: response.getOutputStream()
  • Get the response PrintWriter: response.getWriter()

3. session

session object represents the client A session between the client and the server, which contains all the information generated during the interaction between the client and the server, such as user login information, shopping cart information, etc. It is a javax.servlet.http.HttpSession object.

Function:

  • Get the SessionID: session.getId()
  • Get the creation time of the Session: session.getCreationTime()
  • Get the last access time of Session: session.getLastAccessedTime()
  • Get the maximum inactivity time of Session: session.getMaxInactiveInterval()
  • Set the maximum inactivity time of Session: session .setMaxInactiveInterval(int interval)
  • Get the attributes in the Session: session.getAttribute(String name)
  • Set the attributes in the Session: session.setAttribute(String name, Object value)
  • Remove attributes in Session: session.removeAttribute(String name)
  • Invalidate Session: session.invalidate()

4. application

The application object represents the entire Web application, which contains all ServletContext objects. It is a javax.servlet.ServletContext object.

Function:

  • Get the ServletContext: application.getServletContext()
  • Get the name of the Web application: application.getServletContext(). getServletContextName()
  • Get the version of the web application: application.getServletContext().getMajorVersion() "." application.getServletContext().getMinorVersion()
  • Get the ContextPath of the web application: application.getServletContext().getContextPath()
  • Get the Servlet of the Web application: application.getServletContext().getServlets()
  • Get the Filter of the Web application: application.getServletContext(). getFilters()
  • Get the Listener of the Web application: application.getServletContext().getListeners()
  • Get the resources of the Web application: application.getServletContext().getResource(String path)
  • Get the resource path of the Web application: application.getServletContext().getResourcePaths(String path)
  • Get the MimeType of the Web application: application.getServletContext().getMimeType(String file)

5. out

The out object represents the output stream of the JSP page, which is a java.io.PrintWriter object.

Function:

  • Output the content to the JSP page: out.print(Object obj)
  • Output the newline character to the JSP page: out .println()

6. The page

page object represents the current JSP page, which is a javax.servlet.jsp.PageContext object.

effect:

  • Get the ServletContext of the current JSP page: page.getServletContext()
  • Get the Request of the current JSP page: page.getRequest()
  • Get the Response of the current JSP page: page .getResponse()
  • Get the Session of the current JSP page: page.getSession()
  • Get the Application of the current JSP page: page.getServletContext().getServletContext()
  • Get the JspWriter of the current JSP page: page.getOut()
  • Get the ServletConfig of the current JSP page: page.getServletConfig()
  • Get the Config of the current JSP page: page.getConfig()
  • Get the ErrorPage of the current JSP page: page.getErrorPage()
  • Get the Exception of the current JSP page: page.getException()
  • Get the IsErrorPage of the current JSP page: page.isErrorPage ()
  • Get the IsPage of the current JSP page: page.isPage()
  • Get the IsELIgnored of the current JSP page: page.isELIgnored()
  • Get the IsScriptingIgnored of the current JSP page : page.isScriptingIgnored()

7. The config

#config object represents the configuration information of the current JSP page, which is a javax.servlet.ServletConfig object.

Function:

  • Get the ServletName of the current JSP page: config.getServletName()
  • Get the ContextPath of the current JSP page: config. getServletContext().getContextPath()
  • Get the InitParameter of the current JSP page: config.getInitParameter(String name)
  • Get the InitParameterNames of the current JSP page: config.getInitParameterNames()

8. pageContext

The pageContext object represents the context of the current JSP page, which is a javax.servlet.jsp.PageContext object.

Function:

  • Get the ServletContext of the current JSP page: pageContext.getServletContext()
  • Get the Request of the current JSP page: pageContext. getRequest()
  • Get the Response of the current JSP page: pageContext.getResponse()
  • Get the Session of the current JSP page: pageContext.getSession()
  • Get the Session of the current JSP page Application: pageContext.getServletContext().getServletContext()
  • Get the JspWriter of the current JSP page: pageContext.getOut()
  • Get the ServletConfig of the current JSP page: pageContext.getServletConfig()
  • Get the Config of the current JSP page: pageContext.getConfig()
  • Get the ErrorPage of the current JSP page: pageContext.getErrorPage()
  • Get the Exception of the current JSP page: pageContext.getException( )
  • Get the IsErrorPage of the current JSP page: pageContext.isErrorPage()
  • Get the IsPage of the current JSP page: pageContext.isPage()
  • Get the IsELIgnored of the current JSP page: pageContext.isELIgnored()
  • Get the IsScriptingIgnored of the current JSP page: pageContext.isScriptingIgnored()

9. exception

exception object representation The exception that occurs on the current JSP page is a java.lang.Throwable object.

Function:

  • Get the exception that occurs on the current JSP page: exception.getMessage()
  • Get the exception that occurs on the current JSP page Stack trace: exception.printStackTrace()

The above is the detailed content of Introduce and explain the functions of the nine built-in objects in JSP. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn