Home  >  Article  >  Java  >  Understand the number of built-in objects in JSP. Are you familiar with how many there are?

Understand the number of built-in objects in JSP. Are you familiar with how many there are?

WBOY
WBOYOriginal
2024-02-01 09:09:20558browse

Understand the number of built-in objects in JSP. Are you familiar with how many there are?

Number of JSP built-in objects: 9

Specific code examples:

<%@ page import="javax.servlet.http.*" %>
<%
  // 获取请求对象
  HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();

  // 获取响应对象
  HttpServletResponse response = (HttpServletResponse) pageContext.getResponse();

  // 获取会话对象
  HttpSession session = request.getSession();

  // 获取上下文对象
  ServletContext application = pageContext.getServletContext();

  // 获取配置对象
  ServletConfig config = pageContext.getServletConfig();

  // 获取页面对象
  PageContext pageContext = this.pageContext;

  // 获取异常对象
  Throwable exception = (Throwable) pageContext.getAttribute("javax.servlet.error.exception");

  // 获取输出对象
  JspWriter out = pageContext.getOut();

  // 获取错误码对象
  Integer statusCode = (Integer) pageContext.getAttribute("javax.servlet.error.status_code");
%>

1. request

The request object represents the client's request, which contains information about the request, such as request method, request header, request parameters, request body, etc.

2. response

The response object represents the server's response. It contains information about the response, such as response status code, response header, response body, etc.

3. session

The session object represents the session between the client and the server. It contains information about the session, such as session ID, session attributes, and session timeout. wait.

4. application

The application object represents the context of the Web application. It contains information about the application, such as the root path of the application and the configuration information of the application. , application resources, etc.

5. config

The config object represents the configuration information of the Servlet. It contains information about the Servlet, such as the name of the Servlet, the class name of the Servlet, and the initialization parameters of the Servlet. wait.

6. pageContext

The pageContext object represents the context of the JSP page. It contains information about the JSP page, such as the request object, response object, session object, Context objects, configuration objects, etc.

7. exception

The exception object represents the exception that occurs in the JSP page. It contains information about the exception, such as the type of exception, the message of the exception, and the stack of the exception. Tracking etc.

8. out

out object represents the output stream of the JSP page, which can be used to output content to the client, such as HTML code, text, pictures, etc.

9. statusCode

The statusCode object represents the error code that occurred in the JSP page. It contains information about the error code, such as the number of the error code and the description of the error code. wait.

The above is the detailed content of Understand the number of built-in objects in JSP. Are you familiar with how many there are?. 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