5
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Tomcat8.5.XにおけるsetMaxAgeの挙動(期限付きCookie作成時の注意)

Last updated at Posted at 2016-11-19

8.5.XからsetMaxAgeで期限付きCookieを設定する際のレスポンスヘッダ出力に変更があります。影響があるのはIEのみですが、Tomcatのバージョンを上げる場合は注意が必要です。

挙動の違い
8.5.X系のTomcatから、CookieにsetMaxAge()を設定した場合、レスポンスヘッダの出力項目が変わります。

Cookie.java
Cookie newCookie = new Cookie("CTEST", "kusa");
newCookie.setMaxAge(600);
response.addCookie(newCookie);

レスポンスヘッダの出力
現時点(2016/11)での最新を取得して比較します。
8.0.39 OR 8.5.8

responce
# 8.0.39
HTTP/1.1 200 OK
Set-Cookie: CTEST=kusa; Expires=Sat, 19-Nov-2016 04:02:57 GMT

# 8.5.8
HTTP/1.1 200
Set-Cookie: CTEST=kusa;Max-Age=600

Expiresと出力していた部分が、Max-Ageという出力になっています。IEの場合、Max-Ageを無視するため、setMaxAgeで期限を設定してもセッション間で有効なCookieとなるため注意が必要です。

nw_head.png

cookie_nw.png

上記は、Windows7/IE11のレスポンス結果です。Cookieの有効期限に日付が入って欲しいのですが、MaxAgeを無視しているため、セッションとなっています。動作環境がないため、Edgeでは確認できていません。

setMaxAgeの挙動を 8.0.X以前に戻す場合は以下の方法があるようです。
http://stackoverflow.com/questions/38696081/how-to-change-cookie-processor-to-legacycookieprocessor-in-tomcat-8

5
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?