32. Using The application Object – Example <%@ page import="java.util.Vector" %> <%// Get the global list of shared items Vector<String> sharedItems; synchronized (application) { sharedItems = (Vector<String>) application.getAttribute ("items"); if (sharedItems == null) { sharedItems = new Vector<String>(); application.setAttribute ("items", sharedItems); } } // Append the new item (if exists) String newItem = request.getParameter("item"); if (newItem != null) sharedItems.addElement(newItem); %>
33. Using The application Object – Example (2) <html> <head><title>Global Shared List</title></head> <body> Available shared items: <ol> <% for (String item : sharedItems) { %> <li><%= item %></li> <% } %> </ol> <form method="POST" action="Global-Shared-List.jsp"> <input type="text" name="item"> <input type="submit" value="Add"> </form> </body> </html>