请问各位大大, 在Struts2的action中,有什么方法可以得到这个action是从手机浏览器进来,还是从电脑的浏览器进来吗?有没有什么配置可以得到?

解决方案 »

  1.   

    在action怎么判断屏幕的大小呢?
      

  2.   

    取浏览器的  agent 信息
      

  3.   


    你看判断浏览器UA的,从HTTP头内的request headers 内查找 user-agent 标志,这个UA带有浏览器信息。
    你可以在服务器端过滤出你所知道的手机浏览器或者是其他浏览器UA字符串,依据这个来识别客户端情况。
    这是听别人说的
     
    可以在JS脚本里面获得屏幕分辨率,然后传到ACTION啊
      

  4.   

    <%   
        String userAgent = request.getHeader("User-Agent");   
        if(userAgent.indexOf("Mozilla")!=-1 && userAgent.indexOf("iPhone")!=-1 || userAgent.indexOf("Android")!=-1 ){   
            response.sendRedirect("页面1");   
        }else if(userAgent.indexOf("Opera")!=-1 && userAgent.indexOf("Opera Mini")!=-1 || userAgent.indexOf("BlackBerry")!=-1){   
            response.sendRedirect("页面2");   
        }else if(userAgent.indexOf("Mozilla")!=-1 && userAgent.indexOf("Windows")!=-1){   
            response.sendRedirect("页面3");   
        }else{   
            response.sendRedirect("页面1");   
        }   
    %>