This is an automated email from the ASF dual-hosted git repository. markt pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/master by this push: new e10cfb7 Add session attribute support to the authentication example e10cfb7 is described below commit e10cfb78f6574aa83b8b46c9fd51cc3b34e1a95a Author: Mark Thomas <ma...@apache.org> AuthorDate: Thu Nov 28 09:26:55 2019 +0000 Add session attribute support to the authentication example Primarily to demonstrate session persistence across restarts for authenticated sessions. --- webapps/docs/changelog.xml | 5 ++++ webapps/examples/jsp/security/protected/index.jsp | 30 +++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml index 8d9724e..2693403 100644 --- a/webapps/docs/changelog.xml +++ b/webapps/docs/changelog.xml @@ -96,6 +96,11 @@ of the <code>Connector</code> in the documentation web application. (markt) </fix> + <add> + Add the ability to set and display session attributes in the JSP FORM + authentication example to demonstrate session persistence across + restarts for authenticated sessions. (markt) + </add> </changelog> </subsection> <subsection name="Other"> diff --git a/webapps/examples/jsp/security/protected/index.jsp b/webapps/examples/jsp/security/protected/index.jsp index eacf27a..31122eb 100644 --- a/webapps/examples/jsp/security/protected/index.jsp +++ b/webapps/examples/jsp/security/protected/index.jsp @@ -14,6 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. --%> +<%@ page import="java.util.Enumeration" %> <% if (request.getParameter("logoff") != null) { session.invalidate(); @@ -72,6 +73,35 @@ enter it here: </form> <br><br> +To add some data to the authenticated session, enter it here: +<form method="GET" action='<%= response.encodeURL("index.jsp") %>'> +<input type="text" name="dataName"> +<input type="text" name="dataValue"> +<input type="submit" > +</form> +<br><br> + +<% + String dataName = request.getParameter("dataName"); + if (dataName != null) { + session.setAttribute(dataName, request.getParameter("dataValue")); + } +%> +<p>The authenticated session contains the following attributes:</p> +<table> +<tr><th>Name</th><th>Value</th></tr> +<% + Enumeration<String> names = session.getAttributeNames(); + while (names.hasMoreElements()) { + String name = names.nextElement(); +%> +<tr><td><%= name %></td><td><%= session.getAttribute(name) %></td> +<% + } +%> +</table> +<br><br> + If you have configured this application for form-based authentication, you can log off by clicking <a href='<%= response.encodeURL("index.jsp?logoff=true") %>'>here</a>. --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org