Object | Class | Code Snippet |
out | Represents the JSP writer, which can be used to write data to the response. | <% out.println(“Hello, world!”); out.print(“Today’s date is: ” + new java.util.Date()); %> |
request | Represents the HTTP request. It can be used to access request parameters and headers. | <% String userName = request.getParameter(“username”); out.println(“Hello, ” + userName + “!”); %> |
response | Represents the HTTP response. It can be used to set response headers and cookies. | <% response.setHeader(“Content-Type”, “text/html”); response.setIntHeader(“Refresh”, 1); %> |
session | Represents the HTTP session. It can be used to store data that needs to persist across multiple requests. | <% User user = new User(); user.setName(“John Doe”); session.setAttribute(“user”, user); %> |
application | Represents the ServletContext. It can be used to store data that needs to persist across the entire application. | <% List users = new ArrayList(); users.add(new User(“John Doe”)); users.add(new User(“Jane Doe”)); application.setAttribute(“users”, users); %> |
exception | Represents the exception thrown by the JSP. It can be used to access information about the exception. | <%@ page isErrorPage=”true” %> <% out.println(“An error occurred: ” + exception.getMessage()); %> |
page | Represents the current JSP page. It can be used to access page-scoped variables. | <% page.setAttribute(“message”, “Hello, world!”); %> |
config | Represents the ServletConfig. It can be used to access the initialization parameters of the servlet. | <% String dbUrl = config.getInitParameter(“dbUrl”); String dbUsername = config.getInitParameter(“dbUsername”); String dbPassword = config.getInitParameter(“dbPassword”); // use dbUrl, dbUsername, and dbPassword to connect to the database %> |
pageContext | Represents the PageContext. It can be used to access various JSP-related objects, such as the ServletContext and the JspWriter. | <% JspWriter writer = pageContext.getOut(); writer.println(“Hello, world!”); %> |