/* $Id: SessionExample.java 24-jul-2004.22:16:31 hhildebr Exp $ * */ import java.io.*; import java.text.*; import java.util.*; import javax.servlet.*; import javax.servlet.http.*; /** * Example servlet showing request headers * * @author James Duncan Davidson */ public class SessionExample extends HttpServlet { ResourceBundle rb = ResourceBundle.getBundle("LocalStrings"); public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { response.setContentType("text/html"); PrintWriter out = response.getWriter(); out.println(""); out.println(""); out.println(""); String title = rb.getString("sessions.title"); out.println("" + title + ""); out.println(""); out.println(""); // img stuff not req'd for source code html showing // relative links everywhere! out.println(""); out.println("\"view"); out.println(""); out.println("\"return\""); out.println("

" + title + "

"); HttpSession session = request.getSession(); out.println(rb.getString("sessions.id") + " " + session.getId()); out.println("
"); out.println(rb.getString("sessions.created") + " "); out.println(new Date(session.getCreationTime()) + "
"); out.println(rb.getString("sessions.lastaccessed") + " "); out.println(new Date(session.getLastAccessedTime())); String dataName = request.getParameter("dataname"); String dataValue = request.getParameter("datavalue"); if (dataName != null && dataValue != null) { session.putValue(dataName, dataValue); } out.println("

"); out.println(rb.getString("sessions.data") + "
"); String[] valueNames = session.getValueNames(); if (valueNames != null && valueNames.length > 0) { for (int i = 0; i < valueNames.length; i++) { String name = valueNames[i]; String value = session.getValue(name).toString(); out.println(DemoUtil.HTMLReplace(name) + " = " + DemoUtil.HTMLReplace(value) + "
"); } } out.println("

"); out.print("

"); out.println(rb.getString("sessions.dataname")); out.println(""); out.println("
"); out.println(rb.getString("sessions.datavalue")); out.println(""); out.println("
"); out.println(""); out.println("
"); out.println(""); out.println(""); out.println(""); out.println(""); } public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { doGet(request, response); } }