톰캣 설정
context-1.xml
<Context crossContext="true" .... 생략

context-2.xml 
<Context crossContext="true" .... 생략

테스트
context-1.jsp 

<%

    ServletContext ctx = application.getContext("/context-1");

    Integer counter = (Integer)ctx.getAttribute("counter");

    if (counter == null) {

        counter = 0;

    }

    counter++;

    

    request.setAttribute("counter", counter);

    ctx.setAttribute("counter", counter);

%>


<h1>Context-1</h1>

<h1>현재 카운터는 ${counter}입니다.</h1>


context-2.jsp

<%

    ServletContext ctx = application.getContext("/context-1");

    Integer counter = (Integer)ctx.getAttribute("counter");

    if (counter == null) {

        counter = 0;

    }

    counter++;

    

    request.setAttribute("counter", counter);

    ctx.setAttribute("counter", counter);

%>


<h1>Context-1</h1>

<h1>현재 카운터는 ${counter}입니다.</h1>


출처 : http://jee-bpel-soa.blogspot.com/2009/06/session-sharing-in-apache-tomcat.html
 

 

+ Recent posts