티스토리 뷰
1 getHeader()를 이용한 브라우저 검증
웹 프로젝트를 진행할 때 각가의 브라우저마다 지원하는 내용이 다르기 때문에 꼭! 브라우저를 확인해야한다. 요청 브라우저의 정보는 Header에 각각 저장이되며, 이러한 정보는 HttpServletRequest 객체제 저장되어 전송되게 된다.
HttpServletRequest 객체가 제공하는 getHeader()메소드를 이용하여 요청단의 OS, 및 브라우저를 확인하는 간단한 예제이다.
2 Header에 담기는 정보들
- host
- connection
- accept
- user-agent(OS 및 브라우저의 정보)
- referer(요청 URL)
- accept-encoding
- accept-language
- cookie
3 Jsp source
4 Java source
한가지 중요한정보는 브라우저 검증 순서이다. 내 노트북만 그런줄 알았는데, 회사의 코드도 이렇게 진행이 되어있었다. 순서는 밑과 같은 순서이다.(PC에 많은 종류의 브라우저가 설치되어있으면 이렇게 출력이되는건가 -_-??)
Opera - Chrome - Safari - Firefox - IE 시리즈
이유는 Header의 엘리먼트중 user-agent에 브라우저 정보가 담겨있는데, Opera및 Chrome등이 다음과같은 정보를 전송한다.
Opera 디버그
http-bio-8080-exec-6> [2013-10-16 11:02:54] [HeaderTest] [40] [DEBUG] 엘리먼트->user-agent 내용->Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.69 Safari/537.36 OPR/17.0.1241.45
Chrome 디버그
http-bio-8080-exec-4> [2013-10-16 11:03:36] [HeaderTest] [40] [DEBUG] 엘리먼트->user-agent 내용->Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.69 Safari/537.36
Safari 디버그
http-bio-8080-exec-10> [2013-10-16 11:03:10] [HeaderTest] [40] [DEBUG] 엘리먼트->user-agent 내용->Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/534.57.2 (KHTML, like Gecko) Version/5.1.7 Safari/534.57.2
디버그 정보를 보면 Opera 브라우저의 경우 Opera 뿐만 아니라 Safari, Chrome의 정보가 포함되어있고, Chrome의 경우 Safari의 정보가 같이 출력이 되게된다.
그렇기 때문에 순서를 제멋대로 정하면 Opera브라우저를 사용해도 Chrome을 사용하고있다는 엉뚱한 결과가 튀어나올수도 있기 때문에 조심해야한다.
5 Test
Chrome
http-bio-8080-exec-4> [2013-10-16 10:55:07] [HeaderTest] [40] [DEBUG] 엘리먼트->host 내용->localhost:8080
http-bio-8080-exec-4> [2013-10-16 10:55:07] [HeaderTest] [40] [DEBUG] 엘리먼트->connection 내용->keep-alive
http-bio-8080-exec-4> [2013-10-16 10:55:07] [HeaderTest] [40] [DEBUG] 엘리먼트->accept 내용->text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
http-bio-8080-exec-4> [2013-10-16 10:55:07] [HeaderTest] [40] [DEBUG] 엘리먼트->user-agent 내용->Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.69 Safari/537.36
http-bio-8080-exec-4> [2013-10-16 10:55:07] [HeaderTest] [40] [DEBUG] 엘리먼트->referer 내용->http://localhost:8080/
http-bio-8080-exec-4> [2013-10-16 10:55:07] [HeaderTest] [40] [DEBUG] 엘리먼트->accept-encoding 내용->gzip,deflate,sdch
http-bio-8080-exec-4> [2013-10-16 10:55:07] [HeaderTest] [40] [DEBUG] 엘리먼트->accept-language 내용->ko-KR,ko;q=0.8,en-US;q=0.6,en;q=0.4
http-bio-8080-exec-4> [2013-10-16 10:55:07] [HeaderTest] [40] [DEBUG] 엘리먼트->cookie 내용->COOKIE_SUPPORT=true; GUEST_LANGUAGE_ID=ko_KR; JSESSIONID=D4B8E413A03AC29E594BB5451F2AC553
http-bio-8080-exec-4> [2013-10-16 10:55:07] [HeaderTest] [54] [DEBUG] --------브라우저------
http-bio-8080-exec-4> [2013-10-16 10:55:07] [HeaderTest] [55] [DEBUG] Chrome 입니다.
http-bio-8080-exec-4> [2013-10-16 10:55:07] [HeaderTest] [56] [DEBUG] ----------------------
Opera
http-bio-8080-exec-6> [2013-10-16 11:02:54] [HeaderTest] [40] [DEBUG] 엘리먼트->host 내용->localhost:8080
http-bio-8080-exec-6> [2013-10-16 11:02:54] [HeaderTest] [40] [DEBUG] 엘리먼트->connection 내용->keep-alive
http-bio-8080-exec-6> [2013-10-16 11:02:54] [HeaderTest] [40] [DEBUG] 엘리먼트->accept 내용->text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
http-bio-8080-exec-6> [2013-10-16 11:02:54] [HeaderTest] [40] [DEBUG] 엘리먼트->user-agent 내용->Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.69 Safari/537.36 OPR/17.0.1241.45
http-bio-8080-exec-6> [2013-10-16 11:02:54] [HeaderTest] [40] [DEBUG] 엘리먼트->accept-encoding 내용->gzip,deflate,sdch
http-bio-8080-exec-6> [2013-10-16 11:02:54] [HeaderTest] [40] [DEBUG] 엘리먼트->accept-language 내용->ko-KR,ko;q=0.8,en-US;q=0.6,en;q=0.4
http-bio-8080-exec-6> [2013-10-16 11:02:54] [HeaderTest] [40] [DEBUG] 엘리먼트->cookie 내용->JSESSIONID=369AA2FF344F277B55E00829D129B9E2
http-bio-8080-exec-6> [2013-10-16 11:02:54] [HeaderTest] [48] [DEBUG] --------브라우저------
http-bio-8080-exec-6> [2013-10-16 11:02:54] [HeaderTest] [49] [DEBUG] Opera 입니다.
http-bio-8080-exec-6> [2013-10-16 11:02:54] [HeaderTest] [50] [DEBUG] ----------------------
Safari
http-bio-8080-exec-10> [2013-10-16 11:03:10] [HeaderTest] [40] [DEBUG] 엘리먼트->host 내용->localhost:8080
http-bio-8080-exec-10> [2013-10-16 11:03:10] [HeaderTest] [40] [DEBUG] 엘리먼트->user-agent 내용->Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/534.57.2 (KHTML, like Gecko) Version/5.1.7 Safari/534.57.2
http-bio-8080-exec-10> [2013-10-16 11:03:10] [HeaderTest] [40] [DEBUG] 엘리먼트->accept 내용->text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
http-bio-8080-exec-10> [2013-10-16 11:03:10] [HeaderTest] [40] [DEBUG] 엘리먼트->referer 내용->http://localhost:8080/
http-bio-8080-exec-10> [2013-10-16 11:03:10] [HeaderTest] [40] [DEBUG] 엘리먼트->accept-language 내용->ko-KR
http-bio-8080-exec-10> [2013-10-16 11:03:10] [HeaderTest] [40] [DEBUG] 엘리먼트->accept-encoding 내용->gzip, deflate
http-bio-8080-exec-10> [2013-10-16 11:03:10] [HeaderTest] [40] [DEBUG] 엘리먼트->cookie 내용->JSESSIONID=0851978D584B1F0C2DB76610AA414A96
http-bio-8080-exec-10> [2013-10-16 11:03:10] [HeaderTest] [40] [DEBUG] 엘리먼트->connection 내용->keep-alive
http-bio-8080-exec-10> [2013-10-16 11:03:10] [HeaderTest] [60] [DEBUG] --------브라우저------
http-bio-8080-exec-10> [2013-10-16 11:03:10] [HeaderTest] [61] [DEBUG] Safari 입니다.
http-bio-8080-exec-10> [2013-10-16 11:03:10] [HeaderTest] [62] [DEBUG] ----------------------
IE9
http-bio-8080-exec-6> [2013-10-16 11:10:09] [HeaderTest] [40] [DEBUG] 엘리먼트->accept 내용->text/html, application/xhtml+xml, */*
http-bio-8080-exec-6> [2013-10-16 11:10:09] [HeaderTest] [40] [DEBUG] 엘리먼트->accept-language 내용->ko-KR
http-bio-8080-exec-6> [2013-10-16 11:10:09] [HeaderTest] [40] [DEBUG] 엘리먼트->user-agent 내용->Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)
http-bio-8080-exec-6> [2013-10-16 11:10:09] [HeaderTest] [40] [DEBUG] 엘리먼트->accept-encoding 내용->gzip, deflate
http-bio-8080-exec-6> [2013-10-16 11:10:09] [HeaderTest] [40] [DEBUG] 엘리먼트->host 내용->localhost:8080
http-bio-8080-exec-6> [2013-10-16 11:10:09] [HeaderTest] [40] [DEBUG] 엘리먼트->dnt 내용->1
http-bio-8080-exec-6> [2013-10-16 11:10:09] [HeaderTest] [40] [DEBUG] 엘리먼트->connection 내용->Keep-Alive
http-bio-8080-exec-6> [2013-10-16 11:10:09] [HeaderTest] [40] [DEBUG] 엘리먼트->cache-control 내용->no-cache
http-bio-8080-exec-6> [2013-10-16 11:10:09] [HeaderTest] [40] [DEBUG] 엘리먼트->cookie 내용->JSESSIONID=BAB709E559034EA01F6595E8066F87ED
http-bio-8080-exec-6> [2013-10-16 11:10:09] [HeaderTest] [84] [DEBUG] --------브라우저------
http-bio-8080-exec-6> [2013-10-16 11:10:09] [HeaderTest] [85] [DEBUG] IE9 입니다.
http-bio-8080-exec-6> [2013-10-16 11:10:09] [HeaderTest] [86] [DEBUG] ----------------------
IE8
http-bio-8080-exec-6> [2013-10-16 11:10:11] [HeaderTest] [40] [DEBUG] 엘리먼트->accept 내용->application/x-ms-application, image/jpeg, application/xaml+xml, image/gif, image/pjpeg, application/x-ms-xbap, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*
http-bio-8080-exec-6> [2013-10-16 11:10:11] [HeaderTest] [40] [DEBUG] 엘리먼트->accept-language 내용->ko-KR
http-bio-8080-exec-6> [2013-10-16 11:10:11] [HeaderTest] [40] [DEBUG] 엘리먼트->user-agent 내용->Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E; InfoPath.2)
http-bio-8080-exec-6> [2013-10-16 11:10:11] [HeaderTest] [40] [DEBUG] 엘리먼트->accept-encoding 내용->gzip, deflate
http-bio-8080-exec-6> [2013-10-16 11:10:11] [HeaderTest] [40] [DEBUG] 엘리먼트->host 내용->localhost:8080
http-bio-8080-exec-6> [2013-10-16 11:10:11] [HeaderTest] [40] [DEBUG] 엘리먼트->dnt 내용->1
http-bio-8080-exec-6> [2013-10-16 11:10:11] [HeaderTest] [40] [DEBUG] 엘리먼트->connection 내용->Keep-Alive
http-bio-8080-exec-6> [2013-10-16 11:10:11] [HeaderTest] [40] [DEBUG] 엘리먼트->cache-control 내용->no-cache
http-bio-8080-exec-6> [2013-10-16 11:10:11] [HeaderTest] [40] [DEBUG] 엘리먼트->cookie 내용->JSESSIONID=BAB709E559034EA01F6595E8066F87ED
http-bio-8080-exec-6> [2013-10-16 11:10:11] [HeaderTest] [78] [DEBUG] --------브라우저------
http-bio-8080-exec-6> [2013-10-16 11:10:11] [HeaderTest] [79] [DEBUG] IE8 입니다.
http-bio-8080-exec-6> [2013-10-16 11:10:11] [HeaderTest] [80] [DEBUG] ----------------------
IE7
http-bio-8080-exec-6> [2013-10-16 11:10:13] [HeaderTest] [40] [DEBUG] 엘리먼트->accept 내용->application/x-ms-application, image/jpeg, application/xaml+xml, image/gif, image/pjpeg, application/x-ms-xbap, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*
http-bio-8080-exec-6> [2013-10-16 11:10:13] [HeaderTest] [40] [DEBUG] 엘리먼트->accept-language 내용->ko-KR
http-bio-8080-exec-6> [2013-10-16 11:10:13] [HeaderTest] [40] [DEBUG] 엘리먼트->user-agent 내용->Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; WOW64; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E; InfoPath.2)
http-bio-8080-exec-6> [2013-10-16 11:10:13] [HeaderTest] [40] [DEBUG] 엘리먼트->accept-encoding 내용->gzip, deflate
http-bio-8080-exec-6> [2013-10-16 11:10:13] [HeaderTest] [40] [DEBUG] 엘리먼트->host 내용->localhost:8080
http-bio-8080-exec-6> [2013-10-16 11:10:13] [HeaderTest] [40] [DEBUG] 엘리먼트->dnt 내용->1
http-bio-8080-exec-6> [2013-10-16 11:10:13] [HeaderTest] [40] [DEBUG] 엘리먼트->connection 내용->Keep-Alive
http-bio-8080-exec-6> [2013-10-16 11:10:13] [HeaderTest] [40] [DEBUG] 엘리먼트->cache-control 내용->no-cache
http-bio-8080-exec-6> [2013-10-16 11:10:13] [HeaderTest] [40] [DEBUG] 엘리먼트->cookie 내용->JSESSIONID=BAB709E559034EA01F6595E8066F87ED
http-bio-8080-exec-6> [2013-10-16 11:10:13] [HeaderTest] [72] [DEBUG] --------브라우저------
http-bio-8080-exec-6> [2013-10-16 11:10:13] [HeaderTest] [73] [DEBUG] IE7 입니다.
http-bio-8080-exec-6> [2013-10-16 11:10:13] [HeaderTest] [74] [DEBUG] ----------------------
IE10
http-bio-8080-exec-6> [2013-10-16 11:10:22] [HeaderTest] [40] [DEBUG] 엘리먼트->accept 내용->text/html, application/xhtml+xml, */*
http-bio-8080-exec-6> [2013-10-16 11:10:22] [HeaderTest] [40] [DEBUG] 엘리먼트->accept-language 내용->ko-KR
http-bio-8080-exec-6> [2013-10-16 11:10:22] [HeaderTest] [40] [DEBUG] 엘리먼트->user-agent 내용->Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0)
http-bio-8080-exec-6> [2013-10-16 11:10:22] [HeaderTest] [40] [DEBUG] 엘리먼트->accept-encoding 내용->gzip, deflate
http-bio-8080-exec-6> [2013-10-16 11:10:22] [HeaderTest] [40] [DEBUG] 엘리먼트->host 내용->localhost:8080
http-bio-8080-exec-6> [2013-10-16 11:10:22] [HeaderTest] [40] [DEBUG] 엘리먼트->dnt 내용->1
http-bio-8080-exec-6> [2013-10-16 11:10:22] [HeaderTest] [40] [DEBUG] 엘리먼트->connection 내용->Keep-Alive
http-bio-8080-exec-6> [2013-10-16 11:10:22] [HeaderTest] [40] [DEBUG] 엘리먼트->cache-control 내용->no-cache
http-bio-8080-exec-6> [2013-10-16 11:10:22] [HeaderTest] [40] [DEBUG] 엘리먼트->cookie 내용->JSESSIONID=BAB709E559034EA01F6595E8066F87ED
http-bio-8080-exec-6> [2013-10-16 11:10:22] [HeaderTest] [90] [DEBUG] --------브라우저------
http-bio-8080-exec-6> [2013-10-16 11:10:22] [HeaderTest] [91] [DEBUG] IE10 입니다.
http-bio-8080-exec-6> [2013-10-16 11:10:22] [HeaderTest] [92] [DEBUG] ----------------------
Mobile
http-bio-8080-exec-1> [2013-10-16 11:35:33] [HeaderTest] [40] [DEBUG] 엘리먼트->host 내용->192.168.118.155:8080
http-bio-8080-exec-1> [2013-10-16 11:35:33] [HeaderTest] [40] [DEBUG] 엘리먼트->connection 내용->keep-alive
http-bio-8080-exec-1> [2013-10-16 11:35:33] [HeaderTest] [40] [DEBUG] 엘리먼트->referer 내용->http://192.168.118.155:8080/
http-bio-8080-exec-1> [2013-10-16 11:35:33] [HeaderTest] [40] [DEBUG] 엘리먼트->accept 내용->text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
http-bio-8080-exec-1> [2013-10-16 11:35:33] [HeaderTest] [40] [DEBUG] 엘리먼트->user-agent 내용->Mozilla/5.0 (Linux; U; Android 4.1.2; ko-kr; SHV-E160L Build/JZO54K) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30
http-bio-8080-exec-1> [2013-10-16 11:35:33] [HeaderTest] [40] [DEBUG] 엘리먼트->accept-encoding 내용->gzip,deflate
http-bio-8080-exec-1> [2013-10-16 11:35:33] [HeaderTest] [40] [DEBUG] 엘리먼트->accept-language 내용->ko-KR, en-US
http-bio-8080-exec-1> [2013-10-16 11:35:33] [HeaderTest] [40] [DEBUG] 엘리먼트->accept-charset 내용->utf-8, iso-8859-1, utf-16, *;q=0.7
http-bio-8080-exec-1> [2013-10-16 11:35:33] [HeaderTest] [40] [DEBUG] 엘리먼트->cookie 내용->JSESSIONID=DCC6E55E0FF8064C6FCE570A59935061
http-bio-8080-exec-1> [2013-10-16 11:35:33] [HeaderTest] [60] [DEBUG] --------브라우저------
http-bio-8080-exec-1> [2013-10-16 11:35:33] [HeaderTest] [61] [DEBUG] Safari 입니다.
http-bio-8080-exec-1> [2013-10-16 11:35:33] [HeaderTest] [62] [DEBUG] ----------------------
'JSP & Servlet' 카테고리의 다른 글
JSP Java 기본패키지를 사용한 XML 파싱 (0) | 2015.04.14 |
---|---|
Servlet 3.0에서 지원하는 getServletContext() 메소드 (0) | 2014.12.09 |
- Total
- Today
- Yesterday
- tiles vs sitemesh
- 로컬저장소
- 스프링
- Spring
- 제이보스 스프링4
- extjs6
- mysql 한글깨짐
- extjs
- 마이바티스 resultmp
- extjs 6 테마
- jboss spring4
- with admin option
- maven 로컬저장소
- custom mapping
- mybatis common resultmap
- tiles sitemesh
- 마이바티스 공통 resultmap
- mybatis resultmap
- spring autowired
- 스프링 autowired
- 시간차이구하기
- extjs 6 theme
- local repository
- extjs grid crud
- sencha touch icons
- spring container
- 스프링 컨테이너
- mysql convert
- with grant option
- sencha touch icons list
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |