diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml index af4536506f8d..5a5bac60e507 100644 --- a/webapps/docs/changelog.xml +++ b/webapps/docs/changelog.xml @@ -260,6 +260,10 @@ Examples. Expand the obfuscation of session cookie values in the request header example to JSON responses. (markt) + + Examples. Add the ability to delete session attributes in the servlet + session example. (markt) + diff --git a/webapps/examples/WEB-INF/classes/SessionExample.java b/webapps/examples/WEB-INF/classes/SessionExample.java index 92c3d6b7f97b..76b8fba15b62 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 void doGet(HttpServletRequest request, HttpServletResponse response) thro 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 void doGet(HttpServletRequest request, HttpServletResponse response) thro while (names.hasMoreElements()) { String name = names.nextElement(); String value = session.getAttribute(name).toString(); - out.println(HTMLFilter.filter(name) + " = " + HTMLFilter.filter(value) + "
"); + out.println(HTMLFilter.filter(name) + " = " + HTMLFilter.filter(value)); + out.print("delete"); + out.println("
"); } out.println("

"); @@ -117,7 +125,7 @@ public void doGet(HttpServletRequest request, HttpServletResponse response) thro out.println(""); out.print("

URL encoded "); out.println("");