Java Reference
In-Depth Information
L ISTING 15.3
Continued
<%
// Check the application for the shared properties
Properties props =
(Properties)application.getAttribute(“SPROPERTIES”);
if ( props == null ) {
// If the Properties were not in the application
// load them and put them in the application
props = new Properties();
props.setProperty(“PROP1”, “VAL1”);
props.setProperty(“PROP2”, “VAL2”);
props.setProperty(“PROP3”, “VAL3”);
application.setAttribute(“SPROPERTIES”, props);
}
%>
</body>
</html>
Now you need to create a servlet that will use the shared Properties object that is stored in
the ServletContext . Listing 15.4 contains this JSP.
L ISTING 15.4
GetFromApplication.jsp
<%@ page errorPage=”errorpage.jsp” %>
<%@ page import=”java.util.Properties, java.util.Enumeration” %>
<html>
<head>
<title>Get From Application</title>
</head>
<body>
<%
15
// Check the application for the shared properties
Properties props =
(Properties)application.getAttribute(“PROPERTIES”);
if ( props == null ) {
 
Search WWH ::




Custom Search