Advertisement
Methods | Description |
---|---|
Object setAttribute(String name, Object value) | This method sets an attribute in the page scope |
Object setAttribute(String name, Object value, int scope) | This method returns the attribute in the specified scope. |
Object getAttribute(String name) | This method returns the attribute in the page scope or null. |
Object getAttribute(String name, int scope) | This method returns the attribute in the specified scope or null. |
Object findAttribute(String name) | This method returns the value associated with the attribute searched in page, request, session and application scope, or null. |
void removeAttribute(String name) | This method removes an attribute(if found in any scope). |
void removeAttribute(String name, int scope) | This method removes an attribute from the specified scope(if found). |
String forward(String relativeUrlPath) | This method forwards the ServletRequest and the ServletResponse to another web page in the application. |
ServletRequest getRequest() | Returns the current ServletRequest object. |
ServletResponse getResponse() | Returns the current ServletResponse object. |
ServletConfig getServletConfig() | Returns the current ServletConfig object. |
ServletContext getServletContext() | Returns the current ServletContext object. |
HttpSession getSession() | Returns the current HttpSession object. |
Advertisement
<html>
<head>
<title>JSP pageContext</title>
</head>
<body>
<%
pageContext.setAttribute("Segment", "IT", pageContext.PAGE_SCOPE);
pageContext.setAttribute("Topic", "JSP", pageContext.REQUEST_SCOPE);
pageContext.setAttribute("Website", "DecodeJava", pageContext.SESSION_SCOPE);
pageContext.setAttribute("Year", "2018", pageContext.APPLICATION_SCOPE);
%>
<%
pageContext.forward("DataDisplay.jsp");
%>
</body>
</html>
<html>
<head>
<title>Using JSP pageContext object</title>
</head>
<body>
Accessing the value of attribute "Segment", set in the page scope:
<% out.println(pageContext.getAttribute("Segment", pageContext.PAGE_SCOPE)); %>
<br/>
<br/>
Accessing the value of attribute "Topic", set in request scope :
<% out.println(pageContext.getAttribute("Topic", pageContext.REQUEST_SCOPE)); %>
<br/>
<br/>
Accessing the value of attribute "Website", set in session scope :
<% out.println(pageContext.getAttribute("Website", pageContext.SESSION_SCOPE)); %>
<br/>
<br/>
Accessing the value of attribute "Year", set in application scope :
<% out.println(pageContext.getAttribute("Year", pageContext.APPLICATION_SCOPE)); %>
</body>
</html>
Advertisement
Advertisement
Please check our latest addition
C#, PYTHON and DJANGO
Advertisement