이 코드는 실제로 나에 의해 발견되지 않았지만 회사 프로젝트를 살펴볼 때 실수로 발견되었습니다. 나는 그것이 매우 실용적이라고 생각했기 때문에 그것을 꺼내서 모든 사람들과 공유했습니다.
프레임 워크 : struts2+spring+ibatis,
주요 구현은 HTTP 요청 헤더에서 "사용자 에이전트"에 의존하여이를 완료하는 것입니다. 좋아, 나는 넌센스를 많이 말하지 않고 코드를 업로드하겠습니다.
행동 :
public String execute () {httpservletrequest request = servletactionContext.getRequest (); 부울 ismoblie = judgeismoblie (요청); if (ismoblie) {return "전화"; } "PC"를 반환합니다. } public boolean judgeismoblie (httpservletrequest 요청) {boolean ismoblie = false; 문자열 [] mobileAgents = { "iPhone", "Android", "Phone", "Mobile", "Wap", "Netfront", "Java", "Opera Mobi", "Opera Mini", "Ucweb", "Windows CE", "Symbian", "Series", "Webos", "Sonny", "Dopod", "Nokia", "", "", "", "", "Sams" "palmsource", "xda", "pieplus", "meizu", "midp", "cldc", "motorola", "foma", "docomo", "up.browser", "up.link", "blazer", "hoSin", "huawei", "coolpad", "webOS", ",", ","choowei "" "palmsource", "alcatel", "amoi", "ktouch", "nexian", "ericsson", "philips", "sagem", "wellcom", "bunjalloo", "maui", "smartphone", "iemobile", "spice", "bird", "zte-", "longcos", "pantech", "gionee", "portalmmm", "지그 브라우저", "hiptop", "benq", "haier", "^lct", "320x320", "240x320", "176x220", "w3c", "acs-", "alav", "alca", "amoi", "avan", "", "," "", "" "" "" "" "" "" "" "" "" "" ""avan " "브루", "셀", "cldc", "cmd-", "dang", "doco", "eric", "hipt", "hipt", "inno", "ipaq", "jigs", "kddi", "keji", "leno", "lg-c", "lg-d", ",", ",", ",", ",", ",", "lg-d", "lg-d", "lg-d", "lg-d" "maxo", "midp", "mits", "mmef", "mobi", "mot-", "moto", "mwbp", "nec-", "newt", "noki", "oper", "pall", "pana", "pant", "play", "porx", "Qwap", ""SAGE "" "" "" "" "" "" ""QWAP "sch-", "sec-", "send", "seri", "sgh-", "shar", "sie-", "sie-", "smal", "smar", "sony", "sph-", "symb", "t-mo", "tim-", /*"tosh",* / "tsm-", "upg1", "", "", "", "," "," ",", "", "", "", "," "," "," ",", "tsm-" "voda", "wap-", "wapa", "wapi", "wapp", "wapr", "wabc", "winw", "winw", "xda", "xda-", "googlebot-mobile"}; if (request.getheader ( "user-agent")! = null) {for (String mobileAgent : mobileAgents) {<span style = "margin : 0px; padding : 0px; border : none; color : rgb (0, 130, 0); font-family : consolas, 'courier new', mono; serif; 그는 내부 원칙을 잘 이해하지 못하지만 일반적인 의미를 알고 있습니다. </span> if (request.getheader ( "user-agent"). tolowercase () .indexof (mobileAgent)> = 0) {ismoblie = true; 부서지다; }}} return ismoblie; }struts2
<span style = "화이트 공간 : pre"> </span> <action name = "name"> <result name = "pc"> download/main.jsp </result> <결과 이름 = "전화"> 다운로드/productph.jsp </result> </action>
좋아요, 코드가 너무 많아서 남은 것이 없습니다. . . 매우 간단하지 않습니까?
그것은 나에 의해 쓰여지지 않았지만, 나는이 코드를 보았을 때 무언가를 얻었습니다. 실제로 많은 설정이 요청 헤더에 포함되어 있습니다. 브라우저 나 장치에 관계없이 HTTP를 통해 요청을 호출해야하므로 HTTP 프로토콜이 있어야합니다. HTTP 프로토콜에 능숙하다면 모든 것이 쉽게 수행 할 수 있습니다 (현재 HTTP 프로토콜을 이해하지 못한 다음 열심히 공부하고 좋은 척 할 것임을 의미합니다) ~~.
클라이언트가 휴대 전화/PC이고 다른 페이지로 돌아 오는 것이 내가 공유하는 모든 콘텐츠입니다. 나는 당신이 당신에게 참조를 줄 수 있기를 바랍니다. 그리고 당신이 wulin.com을 더 지원할 수 있기를 바랍니다.