Programming/Apache Tomcat
톰캣[tomcat] context간 세션 공유
Yizi
2018. 7. 6. 11:10
하나의 was에 여러개의 프로젝트(컨텍스트)가 존재할 경우 일반적으로
서로간 세션의 공유가 되지 않는다.
이때 각 컨텍스트간의 세션이 공유될 수 있는 방법을 알아보자.
1. $catalina_home$/conf/context.xml의 변경
1
2
3
4
5
6
7
8
9
10 |
<!-- The contents of this file will be loaded for each web application -->
<Context>
<!-- Default set of monitored resources -->
<WatchedResource>WEB-INF/web.xml</WatchedResource>
<!-- Uncomment this to disable session persistence across Tomcat restarts -->
<!--
<Manager pathname="" />
--> |
cs |
위의 컨텍스트를 아래와 같이 바꿔준다.
1
2
3
4
5
6
7
8
9
10 |
<!-- The contents of this file will be loaded for each web application -->
<Context crossContext="true">
<!-- Default set of monitored resources -->
<WatchedResource>WEB-INF/web.xml</WatchedResource>
<!-- Uncomment this to disable session persistence across Tomcat restarts -->
<!--
<Manager pathname="" />
--> |
cs |
2. $catalina_home$/conf/server.xml 변경
1 |
<Connector connectionTimeout="20000" port="8080" protocol="HTTP/1.1" redirectPort="8443" emptySessionPath="true"/> |
cs |
<Connector>에 emptySessionPath="true" 속성을 추가한다.
3. 세션 셋
1 |
request.getSession().getServletContext().setAttribute("ssUserId", userId); |
cs |
4. 세션 겟
1 |
String ssUserId = (String) request.getSession().getServletContext().getContext("/").getAttribute("ssUserId"); |
cs |