jsp跳转 controller时,ie报404 window.location.href=“test/index” 会变为 window.location.href="test/test/index
在用 时 部分 ie内核浏览器 跳转controller 会报404,映射的链接出现问题
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title></title>
<base href="<%=basePath%>">
//跳转controller
window.location.href="test/index"
//解决
function getContextPath() {
var pathName = document.location.pathname;
var index = pathName.substr(1).indexOf("/");
var result = pathName.substr(0,index+1);
return result;
}
window.location.href=getContextPath()+"/test/index"
这样 ie可正常跳转
onclick带中文参数 ie 也会报错
解决 添加encodeURI()
encodeURI(getContextPath()+"/test/index?name="+name)