This is an automated email from the ASF dual-hosted git repository.
markt pushed a commit to branch 10.1.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/10.1.x by this push:
new aa5b4d0043 Add the ability to delete session attributes.
aa5b4d0043 is described below
commit aa5b4d0043289cf054f531ec55126c980d3572e1
Author: Mark Thomas <[email protected]>
AuthorDate: Mon Dec 2 17:39:05 2024 +0000
Add the ability to delete session attributes.
---
webapps/docs/changelog.xml | 4 ++++
webapps/examples/WEB-INF/classes/SessionExample.java | 14 +++++++++++---
2 files changed, 15 insertions(+), 3 deletions(-)
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index 87270a9843..9dce2c5aaa 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -250,6 +250,10 @@
Examples. Expand the obfuscation of session cookie values in the
request
header example to JSON responses. (markt)
</fix>
+ <add>
+ Examples. Add the ability to delete session attributes in the servlet
+ session example. (markt)
+ </add>
</changelog>
</subsection>
<subsection name = "Other">
diff --git a/webapps/examples/WEB-INF/classes/SessionExample.java
b/webapps/examples/WEB-INF/classes/SessionExample.java
index 92c3d6b7f9..76b8fba15b 100644
--- a/webapps/examples/WEB-INF/classes/SessionExample.java
+++ b/webapps/examples/WEB-INF/classes/SessionExample.java
@@ -1,3 +1,4 @@
+
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
@@ -16,6 +17,8 @@
*/
import java.io.IOException;
import java.io.PrintWriter;
+import java.net.URLEncoder;
+import java.nio.charset.StandardCharsets;
import java.util.Date;
import java.util.Enumeration;
import java.util.ResourceBundle;
@@ -75,7 +78,7 @@ public class SessionExample extends HttpServlet {
String dataName = request.getParameter("dataname");
String dataValue = request.getParameter("datavalue");
- if (dataName != null && dataValue != null) {
+ if (dataName != null) {
session.setAttribute(dataName, dataValue);
}
@@ -85,7 +88,12 @@ public class SessionExample extends HttpServlet {
while (names.hasMoreElements()) {
String name = names.nextElement();
String value = session.getAttribute(name).toString();
- out.println(HTMLFilter.filter(name) + " = " +
HTMLFilter.filter(value) + "<br>");
+ out.println(HTMLFilter.filter(name) + " = " +
HTMLFilter.filter(value));
+ out.print("<a href=\"");
+ out.print(HTMLFilter.filter(
+ response.encodeURL("SessionExample?dataname=" +
URLEncoder.encode(name, StandardCharsets.UTF_8))));
+ out.println("\" >delete</a>");
+ out.println("<br>");
}
out.println("<P>");
@@ -117,7 +125,7 @@ public class SessionExample extends HttpServlet {
out.println("</form>");
out.print("<p><a href=\"");
-
out.print(HTMLFilter.filter(response.encodeURL("SessionExample?dataname=foo&datavalue=bar")));
+
out.print(HTMLFilter.filter(response.encodeURL("SessionExample?dataname=exampleName&datavalue=exampleValue")));
out.println("\" >URL encoded </a>");
out.println("</body>");
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]