|
14 | 14 | See the License for the specific language governing permissions and |
15 | 15 | limitations under the License. |
16 | 16 | --%> |
17 | | -<%@ page import="java.util.Enumeration" %> |
| 17 | +<%@ page import="java.net.URLEncoder" %> |
| 18 | +<%@ page import="java.nio.charset.StandardCharsets" %> |
18 | 19 | <%@ page import="java.security.Principal" %> |
| 20 | +<%@ page import="java.util.Enumeration" %> |
19 | 21 | <%@ page import="org.apache.catalina.TomcatPrincipal" %> |
20 | 22 | <% |
21 | 23 | if (request.getParameter("logoff") != null) { |
@@ -121,31 +123,62 @@ enter it here: |
121 | 123 | %> |
122 | 124 | <br><br> |
123 | 125 |
|
| 126 | +<% |
| 127 | + // Count the existing attributes |
| 128 | + int sessionAttributeCount = 0; |
| 129 | + Enumeration<String> names = session.getAttributeNames(); |
| 130 | + while (names.hasMoreElements()) { |
| 131 | + names.nextElement(); |
| 132 | + sessionAttributeCount++; |
| 133 | + } |
| 134 | +
|
| 135 | + String dataName = request.getParameter("dataName"); |
| 136 | + String dataValue = request.getParameter("dataValue"); |
| 137 | + if (dataName != null) { |
| 138 | + if (dataValue == null) { |
| 139 | + session.removeAttribute(dataName); |
| 140 | + sessionAttributeCount--; |
| 141 | + } else if (sessionAttributeCount < 10) { |
| 142 | + session.setAttribute(dataName, dataValue); |
| 143 | + sessionAttributeCount++; |
| 144 | + } else { |
| 145 | +%> |
| 146 | +<p>Session attribute [<%= util.HTMLFilter.filter(dataName) %>] not added as there are already 10 attributes in the |
| 147 | +session. Delete an attribute before adding another.</p> |
| 148 | +<% |
| 149 | + } |
| 150 | + } |
| 151 | +
|
| 152 | + if (sessionAttributeCount < 10) { |
| 153 | +%> |
124 | 154 | To add some data to the authenticated session, enter it here: |
125 | 155 | <form method="GET" action='<%= response.encodeURL("index.jsp") %>'> |
126 | 156 | <input type="text" name="dataName"> |
127 | 157 | <input type="text" name="dataValue"> |
128 | 158 | <input type="submit" > |
129 | 159 | </form> |
130 | | -<br><br> |
131 | | - |
132 | 160 | <% |
133 | | - String dataName = request.getParameter("dataName"); |
134 | | - if (dataName != null) { |
135 | | - session.setAttribute(dataName, request.getParameter("dataValue")); |
| 161 | + } else { |
| 162 | +%> |
| 163 | +<p>You may not add more than 10 attributes to this session.</p> |
| 164 | +<% |
136 | 165 | } |
137 | 166 | %> |
| 167 | +<br><br> |
| 168 | + |
138 | 169 | <p>The authenticated session contains the following attributes:</p> |
139 | 170 | <table> |
140 | 171 | <tr><th>Name</th><th>Value</th></tr> |
141 | 172 | <% |
142 | | - Enumeration<String> names = session.getAttributeNames(); |
| 173 | + names = session.getAttributeNames(); |
143 | 174 | while (names.hasMoreElements()) { |
144 | 175 | String name = names.nextElement(); |
| 176 | + String value = session.getAttribute(name).toString(); |
145 | 177 | %> |
146 | 178 | <tr> |
147 | 179 | <td><%= util.HTMLFilter.filter(name) %></td> |
148 | | - <td><%= util.HTMLFilter.filter(String.valueOf(session.getAttribute(name))) %></td> |
| 180 | + <td><%= util.HTMLFilter.filter(value) %></td> |
| 181 | + <td><a href='<%= response.encodeURL("index.jsp?dataName=" + URLEncoder.encode(name, StandardCharsets.UTF_8)) %>'>delete</a></td> |
149 | 182 | </tr> |
150 | 183 | <% |
151 | 184 | } |
|
0 commit comments