Step 15- JSP IMPLICIT OBJECTS

ObjectClassCode Snippet
outRepresents 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()); %>
requestRepresents the HTTP request. It can be used to access request parameters and headers.<% String userName = request.getParameter(“username”); out.println(“Hello, ” + userName + “!”); %>
responseRepresents the HTTP response. It can be used to set response headers and cookies.<% response.setHeader(“Content-Type”, “text/html”); response.setIntHeader(“Refresh”, 1); %>
sessionRepresents 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); %>
applicationRepresents 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); %>
exceptionRepresents 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()); %>
pageRepresents the current JSP page. It can be used to access page-scoped variables.<% page.setAttribute(“message”, “Hello, world!”); %>
configRepresents 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 %>
pageContextRepresents 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!”); %>