一、前言
关于定义浏览器IeUtil工具类,实现"判断浏览器类型ie9以下"方法的判断,详情代码示例说明部分。
二、代码示例
import javax.servlet.http.HttpServletRequest;@b@import javax.servlet.http.HttpServletResponse;@b@import org.apache.commons.logging.Log;@b@import org.apache.commons.logging.LogFactory; @b@@b@public class IeUtil {@b@@b@ protected static Log logger = LogFactory.getLog(IeUtil.class);@b@@b@ /**@b@ * 判断浏览器类型ie9以下@b@ * 设置响应头@b@ * @param userAgent@b@ * @return@b@ */@b@ public static boolean isLessIE9(HttpServletRequest request,HttpServletResponse response) {@b@ String userAgent = request.getHeader("User-Agent").toUpperCase();@b@ logger.info("user-agent:" + userAgent );@b@ if (userAgent.indexOf("MSIE 9") > 0 || userAgent.indexOf("MSIE 8") > 0 || userAgent.indexOf("MSIE 7") > 0 || userAgent.indexOf("MSIE 6") > 0) {@b@ response.setCharacterEncoding("UTF-8");@b@ response.setHeader("Content-Type", "text/html");@b@ return true;@b@ }@b@ return false;@b@ }@b@@b@}