IE重定向(Http 302)问题
网站首页 文章专栏 IE重定向(Http 302)问题
IE重定向(Http 302)问题
编辑时间:2019-10-25 16:45 作者:毛毛小妖 浏览量:203 评论数:0

有时候我们需要在代码中进行重定向操作,比如:

@RequestMapping(value = "/index")
public String index(HttpServletRequest request) {
    return "redirect:/demo/hello";
}

这个写法在正常情况下是没有问题的,但是万恶的IE8就不行了,经过实验,我们重定向的地址一定要写完整。所以我们把代码改写成如下:

@RequestMapping(value = "/index")
public String index(HttpServletRequest request) {
    return "redirect:"+getProjectPath(request)+"/demo/hello";
}

public static String getLocalPort() throws MalformedObjectNameException {
    MBeanServer beanServer = ManagementFactory.getPlatformMBeanServer();
    Set<ObjectName> objectNames = beanServer.queryNames(new ObjectName("*:type=Connector,*"),
            Query.match(Query.attr("protocol"), Query.value("HTTP/1.1")));
    String port = objectNames.iterator().next().getKeyProperty("port");
    return port;
}
public static String getLocalIP() {
    String localIP = "127.0.0.1";
    try {
        OK:
        for (Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces(); interfaces.hasMoreElements(); ) {
            NetworkInterface networkInterface = interfaces.nextElement();
            if (networkInterface.isLoopback() || networkInterface.isVirtual() || !networkInterface.isUp()) {
                continue;
            }
            Enumeration<InetAddress> addresses = networkInterface.getInetAddresses();
            while (addresses.hasMoreElements()) {
                InetAddress address = addresses.nextElement();
                if (address instanceof Inet4Address) {
                    localIP = address.getHostAddress();
                    break OK;
                }
            }
        }
    } catch (SocketException e) {
        e.printStackTrace();
    }
    return localIP;
}

 

来说两句吧
最新评论
    还没有人评论哦,快来坐沙发吧!