提交 | 用户 | 时间
|
e7c126
|
1 |
package com.xxl.job.admin.controller.interceptor; |
H |
2 |
|
|
3 |
import com.xxl.job.admin.core.util.FtlUtil; |
|
4 |
import com.xxl.job.admin.core.util.I18nUtil; |
|
5 |
import org.springframework.stereotype.Component; |
|
6 |
import org.springframework.web.servlet.AsyncHandlerInterceptor; |
|
7 |
import org.springframework.web.servlet.ModelAndView; |
|
8 |
|
|
9 |
import javax.servlet.http.Cookie; |
|
10 |
import javax.servlet.http.HttpServletRequest; |
|
11 |
import javax.servlet.http.HttpServletResponse; |
|
12 |
import java.util.HashMap; |
|
13 |
|
|
14 |
/** |
|
15 |
* push cookies to model as cookieMap |
|
16 |
* |
|
17 |
* @author xuxueli 2015-12-12 18:09:04 |
|
18 |
*/ |
|
19 |
@Component |
|
20 |
public class CookieInterceptor implements AsyncHandlerInterceptor { |
|
21 |
|
|
22 |
@Override |
|
23 |
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, |
|
24 |
ModelAndView modelAndView) throws Exception { |
|
25 |
|
|
26 |
// cookie |
|
27 |
if (modelAndView!=null && request.getCookies()!=null && request.getCookies().length>0) { |
|
28 |
HashMap<String, Cookie> cookieMap = new HashMap<String, Cookie>(); |
|
29 |
for (Cookie ck : request.getCookies()) { |
|
30 |
cookieMap.put(ck.getName(), ck); |
|
31 |
} |
|
32 |
modelAndView.addObject("cookieMap", cookieMap); |
|
33 |
} |
|
34 |
|
|
35 |
// static method |
|
36 |
if (modelAndView != null) { |
|
37 |
modelAndView.addObject("I18nUtil", FtlUtil.generateStaticModel(I18nUtil.class.getName())); |
|
38 |
} |
|
39 |
|
|
40 |
} |
|
41 |
|
|
42 |
} |