2013-05-06 59 views
1

如标题所示,我想将手机的请求重定向到特定页面。检测用户代理重定向struts 2中的特定Jsp

另一种方法我想到的是只包含有关用户代理的信息,以便U可以使用JSP变量进行测试,并显示具体的数据仅

我为支柱新手,所以只是一个**期待简单的程序变量... **

+0

你们的服务器支持某种形式的.htaccess的? – SaidbakR 2013-05-06 21:22:46

+0

对不起..我在我的公司under-developent项目..我不知道。告诉我两种条件的解决方案 – 2013-05-07 19:17:06

+0

试试这个:http://stackoverflow.com/questions/9749109/user-agent-for-mobile -application-htaccess-file 和此:http://www.htaccesstools.com/articles/detect-and-redirect-iphone/ – SaidbakR 2013-05-07 21:54:06

回答

0

试试这个。

我的index.jsp

<%-- 
    Document : index 
    Created on : Apr 17, 2013, 7:11:53 PM 
    Author  : Prabhakar 
--%> 


<%@page contentType="text/html" pageEncoding="UTF-8"%> 
<!DOCTYPE html> 
<html> 
    <head> 
     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 
     <title>Detect</title> 
     <% 
     String ua = request.getHeader("User-Agent"); 
     boolean isFirefox = (ua != null && ua.indexOf("Firefox/") != -1); 
     boolean isMSIE = (ua != null && ua.indexOf("MSIE") != -1); 
     response.setHeader("Vary", "User-Agent"); 
     %> 
    </head> 

     <% if(isMSIE){ 
     response.sendRedirect("ie.action"); 

    } else if(isFirefox) { 
     response.sendRedirect("mozilla.action"); 
     }else{ 
     response.sendRedirect("default.action"); 
     } %> 

    </body> 
</html>