Load Balancing/Clustering/Failover Test using Middleware

This JSP shows simple principles of session management by incrementing a counter each time a user accesses a page.

<%! private int totalHits = 0; %> <% session = request.getSession(true); Integer ival = (Integer)session.getAttribute("simplesession.counter"); if (ival == null) ival = new Integer(1); else ival = new Integer(ival.intValue() + 1); session.setAttribute("simplesession.counter", ival); System.out.println("[SessionTest] count = " + ival ); %> <% Integer cnt = (Integer)application.getAttribute("simplesession.hitcount"); if (cnt == null) cnt = new Integer(1); else cnt = new Integer(cnt.intValue() + 1); application.setAttribute("simplesession.hitcount", cnt); System.out.println("[application SessionTest] count = " + ival ); %>

Server Infomation

server bind Address : <%=System.getProperty("jboss.bind.address")%>
server Name : <%=System.getProperty("jboss.server.name")%>

server Home : <%=System.getProperty("jboss.server.home.url")%>
server cluster name : <%=System.getProperty("jboss.partition.name")%>
server udp group : <%=System.getProperty("jboss.partition.udpGroup")%>

referer : <%=request.getHeader("REFERER")%>
serverInfo : <%=request.getSession().getServletContext().getServerInfo() %>
serverName : <%=request.getServerName() %>
serverPort : <%=request.getServerPort() %>
contextPath : <%=request.getContextPath() %>
remoteUser : <%=request.getRemoteUser() %>
SessionId : <%=request.getSession().getId() %>

You have hit this page <%= ival %> time<%= (ival.intValue() == 1) ? "" : "s" %>,
before the session times out.

The value in red is stored in the HTTP session (javax.servlet.http.HttpSession), in an object named simplesession.counter. This object has session scope and its integer value is re-set to 1 when you reload the page after the session has timed out.

You can change the time interval after which a session times out. For more information, see the Session Timeout section under Using Sessions And Session Persistence in Web Applications.

You have hit this page a total of <%= cnt %> time<%= (cnt.intValue() == 1) ? "" : "s" %>!

The value in green is stored in the Servlet Context (javax.servlet.ServletContext), in an object named simplesession.hitcount. This object has application scope and its integer value is incremented each time you reload the page.