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>

解决方案 »

  1.   

    因为<c:redirect是直接跳转页面.
    也就是在生成页面的时候, 执行到这一句就会跳转了.
    用href.location = 'http://www.baidu.com';
      

  2.   

    可是我需要的是一个相对路径,就是例如<c:redirect url="/saveProject.do?method=getProjects"/>这样的。
    如果用location就需要写个绝对路径,例如:window.location.href=http://127.0.0.1:8080/ForestryData/getProject.do?method=getProjects
    如果发布了前面不应该是127.0....
    所以有没有别的方法可以用相对路径跳转的?
      

  3.   

    location.href也可以用相对路径的吧!
      

  4.   

    直接使用<c:redirect url="http://www.baidu.com"/>就可以实现跳转了
    或 javascript   window.location.href="http://www.baidu.com";
    <c:redirect url="http://www.baidu.com"/>与request.getRequestDispatch(request, response).forward("");一致
      

  5.   

    恩发现了,用/ForestryData/getProject.do?method=getProjects  就好了。
    谢谢啦~