1
如標題所示,我想將手機的請求重定向到特定頁面。檢測用戶代理重定向struts 2中的特定Jsp
另一種方法我想到的是隻包含有關用戶代理的信息,以便U可以使用JSP變量進行測試,並顯示具體的數據僅
我爲支柱新手,所以只是一個**期待簡單的程序變量... **
如標題所示,我想將手機的請求重定向到特定頁面。檢測用戶代理重定向struts 2中的特定Jsp
另一種方法我想到的是隻包含有關用戶代理的信息,以便U可以使用JSP變量進行測試,並顯示具體的數據僅
我爲支柱新手,所以只是一個**期待簡單的程序變量... **
試試這個。
我的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>
你們的服務器支持某種形式的.htaccess的? – SaidbakR 2013-05-06 21:22:46
對不起..我在我的公司under-developent項目..我不知道。告訴我兩種條件的解決方案 – 2013-05-07 19:17:06
試試這個: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