Skip to content

Instantly share code, notes, and snippets.

@darbyluv2code
Created April 4, 2017 17:32
Show Gist options
  • Select an option

  • Save darbyluv2code/9303dc2d7cc95a869fe16f2c84e52b81 to your computer and use it in GitHub Desktop.

Select an option

Save darbyluv2code/9303dc2d7cc95a869fe16f2c84e52b81 to your computer and use it in GitHub Desktop.
Fix for JSP session tracking demo
<%@page import="java.util.*" %>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Session example</title>
</head>
<body>
<form action="todo-demo.jsp">
Add new Item : <input type="text" name="theItem">
<input type="submit" value="submit">
<%
//get the TODO item from the session
List <String> items = (List <String>)
session.getAttribute("myTodolist");
//if to do items does not exist then create new one
if(items == null)
{ items= new ArrayList<String>();
session.setAttribute("myTodolist",items);
}
//form of data to add
String theItem=request.getParameter("theItem");
if(theItem!=null)
{
items.add(theItem);
}
%>
<%
for (String temp:items)
{
out.println("<li>"+temp+"</li>");
}
%>
</form>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment