List of usage examples for javax.servlet.http HttpSession getCreationTime
public long getCreationTime();
From source file:org.shareok.data.webserv.HomeController.java
@RequestMapping("/home") public ModelAndView home(HttpServletRequest req, HttpServletResponse res) { ModelAndView model = new ModelAndView(); model.setViewName("home"); HttpSession session = (HttpSession) req.getSession(false); if (null != session) { RedisUser user = (RedisUser) session .getAttribute(ShareokdataManager.getSessionRedisUserAttributeName()); if (null != user) { Cookie userCookie = new Cookie("userId", String.valueOf(user.getUserId())); userCookie.setMaxAge(30 * 60); res.addCookie(userCookie);//from ww w .ja v a2 s . co m model.addObject("user", user); model.addObject("loginTime", session.getCreationTime()); } } return model; }
From source file:net.lightbody.bmp.proxy.jetty.servlet.SessionDump.java
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html"); Page page = new Page(); HttpSession session = request.getSession(getURI(request).indexOf("new") > 0); page.title("Session Dump Servlet: "); TableForm tf = new TableForm(response.encodeURL(getURI(request))); tf.method("POST"); if (session == null) { page.add("<H1>No Session</H1>"); tf.addButton("Action", "New Session"); } else {//from w w w .j a v a 2s .com try { tf.addText("ID", session.getId()); tf.addText("State", session.isNew() ? "NEW" : "Valid"); tf.addText("Creation", new Date(session.getCreationTime()).toString()); tf.addText("Last Access", new Date(session.getLastAccessedTime()).toString()); tf.addText("Max Inactive", "" + session.getMaxInactiveInterval()); tf.addText("Context", "" + session.getServletContext()); Enumeration keys = session.getAttributeNames(); while (keys.hasMoreElements()) { String name = (String) keys.nextElement(); String value = session.getAttribute(name).toString(); tf.addText(name, value); } tf.addTextField("Name", "Property Name", 20, "name"); tf.addTextField("Value", "Property Value", 20, "value"); tf.addTextField("MaxAge", "MaxAge(s)", 5, ""); tf.addButtonArea(); tf.addButton("Action", "Set"); tf.addButton("Action", "Remove"); tf.addButton("Action", "Invalidate"); page.add(tf); tf = null; if (request.isRequestedSessionIdFromCookie()) page.add("<P>Turn off cookies in your browser to try url encoding<BR>"); if (request.isRequestedSessionIdFromURL()) page.add("<P>Turn on cookies in your browser to try cookie encoding<BR>"); } catch (IllegalStateException e) { log.debug(LogSupport.EXCEPTION, e); page.add("<H1>INVALID Session</H1>"); tf = new TableForm(getURI(request)); tf.addButton("Action", "New Session"); } } if (tf != null) page.add(tf); Writer writer = response.getWriter(); page.write(writer); writer.flush(); }
From source file:org.web4thejob.web.panel.DefaultSessionInfoPanel.java
private void prepareContent() { grid.getRows().getChildren().clear(); Row row = new Row(); row.setParent(grid.getRows());//www.j a v a 2s .com Label label = new Label(L10N_LABEL_USER_LOCALE.toString()); label.setParent(row); label = new Label(CoreUtil.getUserLocale().toString()); label.setParent(row); if (ContextUtil.getSessionContext().getSecurityContext().isAdministrator()) { row = new Row(); row.setParent(grid.getRows()); label = new Label(L10N_LABEL_SERVER_LOCALE.toString()); label.setParent(row); label = new Label(Locale.getDefault().toString()); label.setParent(row); row = new Row(); row.setParent(grid.getRows()); label = new Label(L10N_LABEL_SERVER_CHARSET.toString()); label.setParent(row); label = new Label(Charset.defaultCharset().toString()); label.setParent(row); } row = new Row(); row.setParent(grid.getRows()); label = new Label(L10N_LABEL_REMOTE_ADDRESS.toString()); label.setParent(row); label = new Label(Executions.getCurrent().getServerName() + ":" + Executions.getCurrent().getServerPort()); label.setParent(row); row = new Row(); row.setParent(grid.getRows()); label = new Label(L10N_LABEL_LOCAL_ADDRESS.toString()); label.setParent(row); label = new Label(Executions.getCurrent().getLocalAddr() + ":" + Executions.getCurrent().getLocalPort()); label.setParent(row); row = new Row(); row.setParent(grid.getRows()); label = new Label(L10N_LABEL_CLIENT_TYPE.toString()); label.setParent(row); label = new Label(Executions.getCurrent().getUserAgent()); label.setParent(row); row = new Row(); row.setParent(grid.getRows()); label = new Label(L10N_LABEL_DEVICE_TYPE.toString()); label.setParent(row); label = new Label(Executions.getCurrent().getSession().getDeviceType()); label.setParent(row); final ClientInfoEvent info = ContextUtil.getSessionContext().getAttribute(ATTRIB_CLIENT_INFO); if (info != null) { row = new Row(); row.setParent(grid.getRows()); label = new Label(L10N_LABEL_SCREEN_RESOLUTION.toString()); label.setParent(row); label = new Label(info.getScreenWidth() + "x" + info.getScreenHeight() + " px"); label.setParent(row); row = new Row(); row.setParent(grid.getRows()); label = new Label(L10N_LABEL_COLOR_DEPTH.toString()); label.setParent(row); label = new Label(String.valueOf(info.getColorDepth()) + "-bit"); label.setParent(row); } DateFormat formatter = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL, CoreUtil.getUserLocale()); if (Executions.getCurrent().getSession().getNativeSession() instanceof HttpSession) { HttpSession session = (HttpSession) Executions.getCurrent().getSession().getNativeSession(); row = new Row(); row.setParent(grid.getRows()); label = new Label(L10N_LABEL_SESSION_TIMEOUT.toString()); label.setParent(row); label = new Label(String.valueOf(session.getMaxInactiveInterval() / 60) + "'"); label.setParent(row); row = new Row(); row.setParent(grid.getRows()); label = new Label(L10N_LABEL_SESSION_CREATE_TIME.toString()); label.setParent(row); label = new Label(formatter.format(new Date(session.getCreationTime()))); label.setParent(row); row = new Row(); row.setParent(grid.getRows()); label = new Label(L10N_LABEL_SESSION_ACCESSED_TIME.toString()); label.setParent(row); label = new Label(formatter.format(new Date(session.getLastAccessedTime()))); label.setParent(row); } }
From source file:SessionTracker.java
public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { res.setContentType("text/html"); PrintWriter out = res.getWriter(); HttpSession session = req.getSession(true); Integer count = (Integer) session.getAttribute("count"); if (count == null) { count = new Integer(1); } else {/*w w w .ja v a 2s .co m*/ count = new Integer(count.intValue() + 1); } session.setAttribute("count", count); out.println("<html><head><title>SessionSnoop</title></head>"); out.println("<body><h1>Session Details</h1>"); out.println( "You've visited this page " + count + ((count.intValue() == 1) ? " time." : " times.") + "<br/>"); out.println("<h3>Details of this session:</h3>"); out.println("Session id: " + session.getId() + "<br/>"); out.println("New session: " + session.isNew() + "<br/>"); out.println("Timeout: " + session.getMaxInactiveInterval() + "<br/>"); out.println("Creation time: " + new Date(session.getCreationTime()) + "<br/>"); out.println("Last access time: " + new Date(session.getLastAccessedTime()) + "<br/>"); out.println("</body></html>"); }
From source file:de.innovationgate.wgpublisher.WGAUsageStatistics.java
public void addRequestStatistic(HttpServletRequest req, HttpSession sess, WGDatabase db, TMLUserProfile profile) {//from ww w . j a v a 2 s . c o m try { RequestStatistic requestStatistic = new RequestStatistic(); requestStatistic.setDatabase(db.getDbReference()); requestStatistic.setLastAccess(new Date()); requestStatistic.setTask(db.getSessionContext().getTask()); requestStatistic.setUser(db.getSessionContext().getUser()); requestStatistic.setSessionId(sess.getId()); requestStatistic.setSessionCreated(new Date(sess.getCreationTime())); requestStatistic.setNewSession(sess.isNew()); requestStatistic.setRemoteHost(req.getRemoteAddr()); String userAgent = req.getHeader("USER-AGENT"); if (userAgent != null) { requestStatistic.setUserAgent(userAgent); } else { requestStatistic.setUserAgent("(unknown)"); } if (profile != null) { requestStatistic.setProfile(profile.getprofile().getName()); } else { requestStatistic.setProfile("(none)"); } try { _requestStatisticQueue.add(requestStatistic); } catch (IllegalStateException e) { if (!_warnedAboutFullQueue) { _wgaCore.getLog().warn( "Session statistics queue is temporarily full. Currently displayed statistics may not be accurate."); _warnedAboutFullQueue = true; } } } catch (Exception e) { _wgaCore.log.error("Unable to update usage statistics.", e); } }
From source file:SessionSnoop.java
public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { res.setContentType("text/html"); PrintWriter out = res.getWriter(); HttpSession session = req.getSession(); Integer count = (Integer) session.getAttribute("count"); if (count == null) count = new Integer(1); else//w w w . j av a2 s.com count = new Integer(count.intValue() + 1); session.setAttribute("count", count); out.println("<HTML><HEAD><TITLE>Session Count</TITLE></HEAD>"); out.println("<BODY><H1>Session Count</H1>"); out.println("You've visited this page " + count + ((count == 1) ? " time." : " times.")); out.println("<P>"); out.println("<H3>Here is your saved session data:</H3>"); Enumeration e = session.getAttributeNames(); while (e.hasMoreElements()) { String name = (String) e.nextElement(); out.println(name + ": " + session.getAttribute(name) + "<BR>"); } out.println("<H3>Here are some vital stats on your session:</H3>"); out.println("Session id: " + session.getId() + " <I>(keep it secret)</I><BR>"); out.println("New session: " + session.isNew() + "<BR>"); out.println("Timeout: " + session.getMaxInactiveInterval()); out.println("<I>(" + session.getMaxInactiveInterval() / 60 + " minutes)</I><BR>"); out.println("Creation time: " + session.getCreationTime()); out.println("<I>(" + new Date(session.getCreationTime()) + ")</I><BR>"); out.println("Last access time: " + session.getLastAccessedTime()); out.println("<I>(" + new Date(session.getLastAccessedTime()) + ")</I><BR>"); out.println("Requested session ID from cookie: " + req.isRequestedSessionIdFromCookie() + "<BR>"); out.println("Requested session ID from URL: " + req.isRequestedSessionIdFromURL() + "<BR>"); out.println("Requested session ID valid: " + req.isRequestedSessionIdValid() + "<BR>"); out.println("<H3>Test URL Rewriting</H3>"); out.println("Click <A HREF=\"" + res.encodeURL(req.getRequestURI()) + "\">here</A>"); out.println("to test that session tracking works via URL"); out.println("rewriting even when cookies aren't supported."); out.println("</BODY></HTML>"); }
From source file:MyServlet.java
public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { res.setContentType("text/html"); PrintWriter out = res.getWriter(); HttpSession session = req.getSession(); Integer count = (Integer) session.getAttribute("snoop.count"); if (count == null) count = new Integer(1); else//from w ww .j a v a2s . com count = new Integer(count.intValue() + 1); session.setAttribute("snoop.count", count); out.println("<HTML><HEAD><TITLE>SessionSnoop</TITLE></HEAD>"); out.println("<BODY><H1>Session Snoop</H1>"); out.println("You've visited this page " + count + ((count.intValue() == 1) ? " time." : " times.")); out.println("<P>"); out.println("<H3>Here is your saved session data:</H3>"); Enumeration e = session.getAttributeNames(); while (e.hasMoreElements()) { String name = (String) e.nextElement(); out.println(name + ": " + session.getAttribute(name) + "<BR>"); } out.println("<H3>Here are some vital stats on your session:</H3>"); out.println("Session id: " + session.getId() + " <I>(keep it secret)</I><BR>"); out.println("New session: " + session.isNew() + "<BR>"); out.println("Timeout: " + session.getMaxInactiveInterval()); out.println("<I>(" + session.getMaxInactiveInterval() / 60 + " minutes)</I><BR>"); out.println("Creation time: " + session.getCreationTime()); out.println("<I>(" + new Date(session.getCreationTime()) + ")</I><BR>"); out.println("Last access time: " + session.getLastAccessedTime()); out.println("<I>(" + new Date(session.getLastAccessedTime()) + ")</I><BR>"); out.println("Requested session ID from cookie: " + req.isRequestedSessionIdFromCookie() + "<BR>"); out.println("Requested session ID from URL: " + req.isRequestedSessionIdFromURL() + "<BR>"); out.println("Requested session ID valid: " + req.isRequestedSessionIdValid() + "<BR>"); out.println("<H3>Test URL Rewriting</H3>"); out.println("Click <A HREF=\"" + res.encodeURL(req.getRequestURI()) + "\">here</A>"); out.println("to test that session tracking works via URL"); out.println("rewriting even when cookies aren't supported."); out.println("</BODY></HTML>"); }
From source file:UsingContexts.java
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html"); PrintWriter out = response.getWriter(); HttpSession session = request.getSession(true); Integer counter2 = (Integer) getServletContext().getAttribute("counter2"); if (counter2 == null) { counter2 = new Integer(1); } else {//from w w w . j a v a2s . com counter2 = new Integer(counter2.intValue() + 1); } getServletContext().setAttribute("counter2", counter2); Integer counter = (Integer) session.getAttribute("counter"); if (counter == null) { counter = new Integer(1); } else { counter = new Integer(counter.intValue() + 1); } session.setAttribute("counter", counter); out.println("<HTML>"); out.println("<HEAD>"); out.println("<TITLE>"); out.println("Using Contexts"); out.println("</TITLE>"); out.println("</HEAD>"); out.println("<BODY>"); out.println("<H1>Using Contexts</H1>"); out.println("Welcome! You have been here " + counter + " times.<BR>"); out.println("Total page accesses: " + counter2 + "<BR>"); if (session.isNew()) { out.println("This is a new session.<BR>"); } else { out.println("This is not a new session.<BR>"); } out.println("The session ID: " + session.getId() + "<BR>"); out.println("Last time accessed: " + new Date(session.getLastAccessedTime()) + "<BR>"); out.println("Creation time: " + new Date(session.getCreationTime()) + "<BR>"); out.println("Timeout length: " + session.getMaxInactiveInterval() + " seconds<BR>"); out.println("</BODY>"); out.println("</HTML>"); }
From source file:Login.java
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { response.setContentType("text/html"); PrintWriter out = response.getWriter(); out.println("<html>"); out.println("<head>"); out.println("<title>Login</title>"); out.println("</head>"); out.println("<body>"); HttpSession session = request.getSession(); Connection connection = (Connection) session.getAttribute("connection"); if (connection == null) { String userName = request.getParameter("username"); String password = request.getParameter("password"); if (userName == null || password == null) { // prompt the user for her username and password out.println("<form method=\"get\" action=\"Login\">"); out.println("Please specify the following to log in:<p>"); out.println("Username: <input type=\"text\" " + "name=\"username\" size=\"30\"><p>"); out.println("Password: <input type=\"password\" " + "name=\"password\" size=\"30\"><p>"); out.println("<input type=\"submit\" value=\"Login\">"); out.println("</form>"); } else {//from w ww . ja va 2 s .c om // create the connection try { connection = DriverManager.getConnection("jdbc:oracle:thin:@dssw2k01:1521:orcl", userName, password); } catch (SQLException e) { out.println("Login doGet() " + e.getMessage()); } if (connection != null) { // store the connection session.setAttribute("connection", connection); response.sendRedirect("Login"); return; } } } else { String logout = request.getParameter("logout"); if (logout == null) { // test the connection Statement statement = null; ResultSet resultSet = null; String userName = null; try { statement = connection.createStatement(); resultSet = statement.executeQuery("select initcap(user) from sys.dual"); if (resultSet.next()) userName = resultSet.getString(1); } catch (SQLException e) { out.println("Login doGet() SQLException: " + e.getMessage() + "<p>"); } finally { if (resultSet != null) try { resultSet.close(); } catch (SQLException ignore) { } if (statement != null) try { statement.close(); } catch (SQLException ignore) { } } out.println("Hello " + userName + "!<p>"); out.println("Your session ID is " + session.getId() + "<p>"); out.println("It was created on " + new java.util.Date(session.getCreationTime()) + "<p>"); out.println("It was last accessed on " + new java.util.Date(session.getLastAccessedTime()) + "<p>"); out.println("<form method=\"get\" action=\"Login\">"); out.println("<input type=\"submit\" name=\"logout\" " + "value=\"Logout\">"); out.println("</form>"); } else { // close the connection and remove it from the session try { connection.close(); } catch (SQLException ignore) { } session.removeAttribute("connection"); out.println("You have been logged out."); } } out.println("</body>"); out.println("</html>"); }
From source file:SessionLogin.java
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { response.setContentType("text/html"); PrintWriter out = response.getWriter(); out.println("<html>"); out.println("<head>"); out.println("<title>Login</title>"); out.println("</head>"); out.println("<body>"); HttpSession session = request.getSession(); SessionConnection sessionConnection = (SessionConnection) session.getAttribute("sessionconnection"); Connection connection = null; if (sessionConnection != null) { connection = sessionConnection.getConnection(); }//w ww. j a va 2s . c o m if (connection == null) { String userName = request.getParameter("username"); String password = request.getParameter("password"); if (userName == null || password == null) { // prompt the user for her username and password out.println("<form method=\"get\" action=\"SessionLogin\">"); out.println("Please specify the following to log in:<p>"); out.println("Username: <input type=\"text\" " + "name=\"username\" size=\"30\"><p>"); out.println("Password: <input type=\"password\" " + "name=\"password\" size=\"30\"><p>"); out.println("<input type=\"submit\" value=\"Login\">"); out.println("</form>"); } else { // create the connection try { connection = DriverManager.getConnection("jdbc:oracle:thin:@dssw2k01:1521:orcl", userName, password); } catch (SQLException e) { out.println("Login doGet() " + e.getMessage()); } if (connection != null) { // store the connection sessionConnection = new SessionConnection(); sessionConnection.setConnection(connection); session.setAttribute("sessionconnection", sessionConnection); response.sendRedirect("SessionLogin"); return; } } } else { String logout = request.getParameter("logout"); if (logout == null) { // test the connection Statement statement = null; ResultSet resultSet = null; String userName = null; try { statement = connection.createStatement(); resultSet = statement.executeQuery("select initcap(user) from sys.dual"); if (resultSet.next()) userName = resultSet.getString(1); } catch (SQLException e) { out.println("Login doGet() SQLException: " + e.getMessage() + "<p>"); } finally { if (resultSet != null) try { resultSet.close(); } catch (SQLException ignore) { } if (statement != null) try { statement.close(); } catch (SQLException ignore) { } } out.println("Hello " + userName + "!<p>"); out.println("Your session ID is " + session.getId() + "<p>"); out.println("It was created on " + new java.util.Date(session.getCreationTime()) + "<p>"); out.println("It was last accessed on " + new java.util.Date(session.getLastAccessedTime()) + "<p>"); out.println("<form method=\"get\" action=\"SessionLogin\">"); out.println("<input type=\"submit\" name=\"logout\" " + "value=\"Logout\">"); out.println("</form>"); } else { // close the connection and remove it from the session try { connection.close(); } catch (SQLException ignore) { } session.removeAttribute("sessionconnection"); out.println("You have been logged out."); } } out.println("</body>"); out.println("</html>"); }