月眸


IE重定向(Http 302)问题

毛毛小妖 2019-10-25 25浏览 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;
}

 

最后修改:2019-10-25 16:42:34 © 著作权归作者所有
如果觉得我的文章对你有用,请随意赞赏
扫一扫支付

上一篇

发表评论

说点什么吧~

评论列表

还没有人评论哦~赶快抢占沙发吧~