小弟目前正在学jsp
我在jsp中有这样两句 out.println("<script>alert('你已经订购了此商品!');window.close();</script>");
<jsp:forward page="index.html"/>为什么这里对话框不弹出呢,而是直接执行下面的jsp语句。

解决方案 »

  1.   


    <% 
    out.print("<script>alert('你已经订购了此商品!');window.location.href='index.html';</script>");
    %>
      

  2.   

    <script type="text/javascript"></script>都是需要触发的,你这样单独写在那是不会调用script的
      

  3.   

    刚才回复错了,请谅解,正确的应该是:out.println("<script type='text/javascript'>alert('你已经订购了此商品!');window.location.href='index.html';</script>");
      

  4.   

    大哥你都window.close()就关闭了这个窗口了
      

  5.   

    你不要  window.close()这样整个窗口就关闭了  4楼这个可以  不要关闭窗口
      

  6.   

    新建个jsp看看效果:<%@ page language="java" import="java.util.*" pageEncoding="gbk"%>
    <%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
    %><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
      <head>
        <base href="<%=basePath%>">
        <title>My JSP 'MyJsp.jsp' starting page</title>
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">    
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
      </head>
      
      <body>
        This is my JSP page. <br>
        <% 
         out.print("开始执行代码<br/>");
         out.print("<script language='javascript'>alert('你已经订购了此商品!');window.location.href='index.html';</script>"); %>
         out.print("<br/>结束执行代码");
      </body>
    </html>