//File Name: application_page1.jsp
<%
String theSharedObject = "JSP is cool";
application.setAttribute("message", theSharedObject);
%>
<HTML>
<HEAD>
<TITLE>Application Object - Page 1</TITLE>
</HEAD>
<BODY>
This page sets data that can be retrieved by other pages in the application.<P>
Click <a href="application_page2.jsp">here</a> to see this in action.
</BODY>
</HTML>
//File Name:application_page2.jsp
<%
// getAttribute() returns a java.lang.Object, so need to cast
String theSharedObject = (String) application.getAttribute("message");
%>
<HTML>
<HEAD>
<TITLE>Application Object - Page 2</TITLE>
</HEAD>
<BODY>
This page retrieves the message that was stored in the <i>application</i> object by another page.
<P>
The message is <b><%= theSharedObject %></b>
</BODY>
</HTML>
|