๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
Java

[Java] ๊ฐ™์€ ๋„๋ฉ”์ธ ์‚ฌ์šฉ์‹œ session๊ฐ’ null๋กœ ๋ณ€๊ฒฝ๋˜๋Š” ํ˜„์ƒ

by cheezzz 2021. 12. 10.
๋ฐ˜์‘ํ˜•

Tomcat์— ๊ฐ™์€ ๋„๋ฉ”์ธ ๋‹ค๋ฅธ ํฌํŠธ๋กœ ์ปจํ…Œ์ด๋„ˆ๋ฅผ a, b๋กœ ๋ถ„๋ฆฌํ•œ ์ƒํƒœ์—์„œ
a ์ปจํ…Œ์ด๋„ˆ์—์„œ setAttribute์œผ๋กœ ์ƒ์„ฑํ•˜๊ณ  ์ €์žฅํ•œ session ๊ฐ’์ด b ์ปจํ…Œ์ด๋„ˆ์˜ ํŽ˜์ด์ง€๋กœ ์ด๋™ํ•˜๋ฉด์„œ null๋กœ ๋ณ€๊ฒฝ๋˜๋Š” ํ˜„์ƒ์ด ์žˆ์—ˆ์Šต๋‹ˆ๋‹ค.

๊ตฌ๊ธ€๋ง ๊ฒฐ๊ณผ,
๊ฐ™์€ ๋„๋ฉ”์ธ(๋˜๋Š” ์•„์ดํ”ผ) ๋‹ค๋ฅธ ํฌํŠธ์—์„œ๋Š” ํŽ˜์ด์ง€ ์ด๋™ ์‹œ ํ†ฐ์บฃ์—์„œ ์ €์žฅํ•˜๋Š” JSESSIONID ๋ผ๋Š” HTTP ์„ธ์…˜ID ๊ฐ’์ด ๊ฐฑ์‹ ๋œ๋‹ค๊ณ  ํ•ฉ๋‹ˆ๋‹ค.

์—ฌ๋Ÿฌ๊ฐ€์ง€ ํ•ด๊ฒฐ๋ฐฉ์•ˆ์ด ์žˆ์—ˆ์ง€๋งŒ ๋‚˜์˜ ๊ฒฝ์šฐ ์•„๋ž˜์™€ ๊ฐ™์ด ํ•ด๊ฒฐํ•˜์˜€์Šต๋‹ˆ๋‹ค.

 

๋‘ ์ปจํ…Œ์ด๋„ˆ์˜ context path๊ฐ€ ๊ฐ™์•„ ์„ธ์…˜ ์ •๋ณด๋ฅผ ๋ฎ์–ด์“ฐ๊ฒŒ ๋˜์—ˆ๊ธฐ ๋•Œ๋ฌธ์—, ๋‘ ์ปจํ…Œ์ด๋„ˆ์˜ context path ๋ฅผ ๋‹ค๋ฅด๊ฒŒ ๋ณ€๊ฒฝ.

Tomcat์˜ server.xml ํŒŒ์ผ path ๋‹ค๋ฅด๊ฒŒ ์ˆ˜์ •
ํŒŒ์ผ ๊ฒฝ๋กœ : apache-tomcat-7.0.96/conf/server.xml

// a ์ปจํ…Œ์ด๋„ˆ
Context docBase="AContainer" path="" reloadable="true" source="org.eclipse.jst.j2ee.server:AContainer"/>

 

//  b ์ปจํ…Œ์ด๋„ˆ
<Context docBase="BContainer" path="/work" reloadable="true" source="org.eclipse.jst.jee.server::BContainer"/>
๋ฐ˜์‘ํ˜•

๋Œ“๊ธ€