JSP文件中,添加如下代码,明明都if(0)了,请问为什么总会跳转到baidu页面呢?
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
....
<head>
<script language="javascript">
if(0)
{
document.getElementById("go").innerHTML='<c:redirect url="http://www.baidu.com"/>';
}
else
{
document.getElementById("go").innerHTML='cat';
}
</script>
</head>
<body id="go"> </body>
</html:html>
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
....
<head>
<script language="javascript">
if(0)
{
document.getElementById("go").innerHTML='<c:redirect url="http://www.baidu.com"/>';
}
else
{
document.getElementById("go").innerHTML='cat';
}
</script>
</head>
<body id="go"> </body>
</html:html>
也就是在生成页面的时候, 执行到这一句就会跳转了.
用href.location = 'http://www.baidu.com';
如果用location就需要写个绝对路径,例如:window.location.href=http://127.0.0.1:8080/ForestryData/getProject.do?method=getProjects
如果发布了前面不应该是127.0....
所以有没有别的方法可以用相对路径跳转的?
或 javascript window.location.href="http://www.baidu.com";
<c:redirect url="http://www.baidu.com"/>与request.getRequestDispatch(request, response).forward("");一致
谢谢啦~