1) Create a JSP page, elImplicitObjects.jsp in the WebContent folder of the Web Application
2) Add the following configuration to the WebContent/WEB-INF/web.xml file of the web application
3) Test the page by typing the following URL in the browser (with no whitespaces in the URL):
Note: To see cookie value, refresh the page that shows up after typing the above link
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<html>
<head>
<title>EL Implicit Objects Demo</title>
</head>
<body>
<%
application.setAttribute("test","test-value");
request.setAttribute("test2","test-value2");
Cookie c = new Cookie("testCookie", "testCookieValue");
response.addCookie(c);
%>
applicationScope implicit Object: ${applicationScope.test} <br/>
requestScope implicit Object: ${requestScope.test2} <br/>
<br/>
initParam implicit Object: ${initParam.paramName} <br/>
<br/>
param implicit Object: ${param.username} <br/>
paramValues implicit Object: ${paramValues.colors[1]} <br/>
<br/>
header implicit Object: ${header.host} <br/>
cookie implicit Object: ${cookie.testCookie.value} <br/>
</body>
</html>
2) Add the following configuration to the WebContent/WEB-INF/web.xml file of the web application
<context-param>
<param-name>contextParam</param-name>
<param-value>contextValue</param-value>
</context-param>
3) Test the page by typing the following URL in the browser (with no whitespaces in the URL):
http://localhost:8080/TestWebApp/elImplicitObjects.jsp?username=dinesh&colors=red&colors=saffron
Note: To see cookie value, refresh the page that shows up after typing the above link
No comments:
Post a Comment