<% PageContext pageContext = null; String message = "Hello World!"; pageContext.setAttribute("message", message, PageContext.PAGE_SCOPE); %>
<% PageContext pageContext = null; String name = "Alice"; pageContext.setAttribute("name", name, PageContext.REQUEST_SCOPE); %>
<% PageContext pageContext = null; User user = new User("Alice", "password"); pageContext.setAttribute("user", user, PageContext.SESSION_SCOPE); %>
<% PageContext pageContext = null; String version = "1.0"; pageContext.setAttribute("version", version, PageContext.APPLICATION_SCOPE); %>Explanation: Here, we are setting an attribute "version" with value "1.0" in the application scope. This means the attribute will be accessible throughout the application. Package library: javax.servlet.jsp In all of these examples, we are using the PageContext.setAttribute() method to set an attribute with a specified scope. The package library used is javax.servlet.jsp.