Here I use the command line to create a cluster in the application server Glassfish 3.1 and add 2 instances to it.
Once the cluster is created I deploy an enterprise application and run it in both instances.
1: @WebServlet(name = "LogoutServlet", urlPatterns = {"/logout"})
2: public class LogoutServlet extends HttpServlet {
3: @Override
4: protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
5: //Invalidates the session
6: request.getSession(false).invalidate();
7: // Redirects back to the initial page.
8: response.sendRedirect(request.getContextPath());
9: }
10: }