?

test.jsp<%@ page contentType="text/html;charset=GBK"%>
<HTML>
 <HEAD>
  <TITLE> New Document </TITLE>
  <META NAME="Generator" CONTENT="EditPlus">
  <META NAME="Author" CONTENT="">
  <META NAME="Keywords" CONTENT="">
  <META NAME="Description" CONTENT="">
 </HEAD>
 <BODY>
  <form action ="test2.jsp">
     <input type="text" name="txt" id="txtid" >
     <input type="hidden" name="hid" id="hidid" >
     <input type="submit" value="Test">
 </form>
 </BODY>
</HTML>
test2.jsp<%@ page contentType="text/html;charset=GBK"%>
<html>
    <%
      String name = request.getParameter("Name");
      out.println("<script> alert('出错了');history.go(-1);</script>");
    %>
    
  <head></head>
  <body>
     <script type="text/javascript">
       alert("我还在呢");
       location.href='test2.jsp';
     </script>
     ffffffffff
  </body>
</html><script type="text/javascript">
       alert("我还在呢");
       location.href='test2.jsp';
     </script>
     ffffffffff这段代码执行的吗,我试没用弹出(我还在呢)!但上次我做的时候(没有<script type...>.....<script>而是往数据库里插入数据,它执行了),这是为什么?
history.go(-1)扫行,后在的代码到底还运行吗

解决方案 »

  1.   

    out.println("<script> alert('出错了');history.go(-1);</script>");这里返回了,应该不会看到后边的吧.
      

  2.   

     <%
          String name = request.getParameter("Name");
          out.println("<script> alert('出错了');history.go(-1);</script>");
        %>
    不往后走了,
    <script type="text/javascript">
                 alert("我还在呢");
                 location.href='test2.jsp';
            </script>
    接着往后走沙发!~
      

  3.   

    jsp执行过程是这样的:先执行scriplet然后dom顺序执行dom中有机会跳转或loaction到其他页面的话,则不会往下执行例如:你在之前out.println(" <script> alert('出错了');history.go(-1); </script>");那么后面的代码就不会执行了如果他没机会history的话 那么就在 location.href='test2.jsp';这个地方转向了,下面的代码就不会被执行。明白了吗???
      

  4.   

    但按2楼的改,就要执行history.go(-1)后面的代码,jsp转成java源文件:  out.write("\r\n");
          out.write("<html>\r\n");
          out.write("    ");      String name = request.getParameter("Name");
         
          out.write("\r\n");
          out.write("     ");      if(name==null){
          
          out.write("\r\n");
          out.write("       <script type=\"text/html\">\r\n");
          out.write("       \t alert(\"出划\");\r\n");
          out.write("       \t history.go(-1);\r\n");
          out.write("       </script>\r\n");
          out.write("      ");      }
          //out.println("<script type='text/javascript'> alert();hisory.go(-1)</script>");
        
          out.write("\r\n");
          out.write("    \r\n");
          out.write("  <head></head>\r\n");
          out.write("  <body>\r\n");
          out.write("  \t  <script type=\"text/javascript\">\r\n");
          out.write("  \t  \t alert(\"我还在呢\");\r\n");
          out.write("  \t  \t return ;\r\n");
          out.write("  \t  \t location.href='test2.jsp';\r\n");
          out.write("  \t  </script>\r\n");
          out.write("  \t  ");      out.println("ssssssssssss");
         
          out.write("\r\n");
          out.write("  \t  ffffffffff\r\n");
          out.write("  </body>\r\n");
          out.write("</html>");
    还不明白这两者的区别?
      

  5.   


    刚才说的不清楚,接着往后走是指'test2.jsp'; 往这里走
      

  6.   

    但上次我做的时候(没有 <script type...>..... <script>而是往数据库里插入数据,它执行了),这是为什么? =========================================================
    这是因为这时候你没有location.href='test2.jsp';  这条了,所以不会跳转到任何地方从而结束程序的运行,所以数据库插入数据执行了