81041
2019-10-31 2edd919b4ae7eb04a766ba034518ab420f4860f9
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
32
33
34
35
36
37
38
39
40
41
42
43
44
package com.fgkj.actions;
 
import javax.servlet.http.HttpSession;
 
import com.fgkj.dao.CheckMobile;
 
public class CheckClientAction extends ActionUtil{
    /** 
     * 检查访问方式是否为移动端 
     *  
     * @Title: check 
     * @Date : 2014-7-7 下午03:55:19 
     * @param request 
     * @throws IOException  
     */  
    public String check(){  
        boolean isFromMobile=false;  
          
        HttpSession session= getSession();  
       //检查是否已经记录访问方式(移动端或pc端)  
       //if(null==session.getAttribute("ua")){  
            try{  
                //获取ua,用来判断是否为移动端访问  
                String userAgent = getRequest().getHeader( "USER-AGENT" ).toLowerCase();    
                if(null == userAgent){    
                    userAgent = "";    
                }  
                isFromMobile=CheckMobile.check(userAgent);  
                //判断是否为移动端访问  
                if(isFromMobile){  
                   // System.out.println("移动端访问"); 
                    //session.setAttribute("ua","mobile");
                    
                    return SUCCESS;
                } else {  
                    //System.out.println("pc端访问");
                   //session.setAttribute("ua","pc");  
                    return NONE;
                }  
            }catch(Exception e){}  
        //}  
        return NONE;  
    } 
}