简体   繁体   中英

Session Replication on JBoss EAP is not working

I am trying to get Session Replication to work... We have two nodes, I start the following JSP code on node1 and I watch the counter going up.. I then shutdown the node and I would think that the counter would still have the right and working on node2.. We do get moved to node2, but it starts a new session..

Below is the JSP code:

<% /*
This is an example that shows sessions in use within a JSP.

It's the simplest possible demo - a visit counter, but a
counter for the number of times that the current user has
visited during the current session.
*/

/* Get value, or set to zero if this is a new session */

String val = (String) session.getAttribute("previouses");
if ( val == null ) val = "0";

/* Convert to number, increment, save back into session */
int n = Integer.parseInt(val);
n++;
session.setAttribute("previouses",Integer.toString(n));

/* Also pick up the hosts so that we can echo this in the
reply page (great for testing load balancer and sticky
session algorithms on our training courses! */
String hostipr = request.getRemoteHost();
String hostipl = request.getServerName();

/* ------------------------------------------------- */

%>
<html>
<head>
<title>Sessions using a JSP</title>
</head>
<body>
<h1>Sessions in a JSP</h1>
This example program shows the use of a session within a
Java Server page (JSP). It's the simplest possible example,
counting the number of times that the user has visited in
the current session.<br /><br />
<b>Details from the session</b><br/>
Requested session:<%=request.getRequestedSessionId()%><br/>
Session: <%= session.getId()%><br/>
Generating or back end host: <%= hostipl %><br />
Accessing or front end host: <%= hostipr %><br />


Count: <%= n %><br/>
</body>
</html>

You need to have web.xml with <distributable/> tag for JBoss to enable session replication for your web application. Refer to http://docs.jboss.org/jbossas/docs/Clustering_Guide/beta422/html/clustering-http-app.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM