<%@ taglib uri="/weblogic/taglib/session" prefix="session" %>

<% 
  String action = request.getParameter("action");
  if ( (action != null) && action.equals("add") ) {
    String addName = request.getParameter("addName");
    String addValue= request.getParameter("addValue");
    if ((addName != null) && (addValue != null)) {
      session.setAttribute(addName, addValue);
    }
  }

  if ( (action != null) && action.equals("delete") ) {
    String delName = request.getParameter("delName");
    if ((delName != null)) {    
      session.removeAttribute(delName);
    }
  }
%>

<html>
<head>
<title>Session Cart</title>
</head>

<body>
<font face="Helvetica">

<h1>Session Cart</h1>

<blockquote>

<p> This simple JavaServer Page uses a custom tag to list the 
contents of your HTTP session, then allows you to add
String values to the session. 

<h2>String values currently in your session:</h2>

<table width=500 border=1>
  <tr bgcolor=#dddddd> 
    <th width=40%>Attribute Name</th>   
    <th width=40%>Attribute Value</th> 
    <th width=20%>Delete</th>
  </tr>

<session:list>
  <tr>
    <td><%= name %></td>     
    <td><%= value %></td>
    <td><a href="<%=request.getRequestURI()%>?action=delete&delName=<%=name%>">
        <img border=0 src="<%= request.getContextPath() %>/images/trash.gif"> delete
        </a>
    </td>
  </tr>
</session:list>

</table>

<form action="<%=request.getRequestURI()%>"> 
<input type="hidden" name="action" value="add">
<table>
<tr><td colspan=2>Add a new name/value pair to the session</td></tr>
<tr><td>Name:</td><td><input type=text name=addName></td></tr>
<tr><td>Value:</td><td><input type=text name=addValue></td></tr>
<tr><td></td><td><input type=submit></td></tr>
</table>

</form>

</blockquote>

</font>
</body>
</html>
