Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Basic clustering JSP
<meta http-equiv="Refresh" content="0;url=jsp/testSession.jsp">
<jboss-web>
<replication-config>
<!--
Possible Values:
ACCESS
SET_AND_GET
SET_AND_NON_PRIMITIVE_GET
SET
-->
<replication-trigger>SET_AND_NON_PRIMITIVE_GET</replication-trigger>
<!--
Possible Values:
SESSION
ATTRIBUTE
FIELD
-->
<replication-granularity>SESSION</replication-granularity>
</replication-config>
</jboss-web>
<%@page import="java.util.*, java.lang.reflect.*, javax.servlet.http.HttpSession "%>
<%
String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort();
String cPath = request.getContextPath();
String sPath = request.getServletPath();
// JBOSS 5
// String nodeId = System.getProperty("jboss.node.name");
// String hostName = System.getProperty("jboss.server.name");
// JBOSS 6
String nodeId = System.getProperty("jboss.server.name");
String hostName = System.getProperty("java.rmi.server.hostname");
String variableString = (String)session.getAttribute("SESSION_TEST_VARIABLE");
int count = 0;
if(variableString != null)
{
count = Integer.parseInt(variableString);
count++;
}
session.setAttribute("SESSION_TEST_VARIABLE", String.valueOf(count));
%>
<html>
<body bgcolor=white>
<table columns=1>
</table>
<table columns=2>
<tr><td><font color=blue>The sessionId is: </font></td><td><%=session.getId() %></td>
<tr><td><font color=blue>The sessionObj is: </font></td><td><%=session %></td>
<tr><td><font color=blue>The nodeId is: </font></td><td><%=nodeId %></td>
<tr><td><font color=blue>The server hostName is: </font></td><td><%=hostName %></td>
<tr><td><font color=blue># of requests placed on session: </font></td><td><%=count %></td>
</table>
</body>
</html>
<?xml version="1.0"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4">
<distributable/>
<description>test session</description>
</web-app>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment