日期:2014-05-17  浏览次数:20685 次

Jsp学习中的小问题
小弟目前正在学jsp
我在jsp中有这样两句

 out.println("<script>alert('你已经订购了此商品!');window.close();</script>");
<jsp:forward page="index.html"/>

为什么这里对话框不弹出呢,而是直接执行下面的jsp语句。

------解决方案--------------------
<script type="text/javascript"></script>都是需要触发的,你这样单独写在那是不会调用script的
------解决方案--------------------
刚才回复错了,请谅解,正确的应该是:out.println("<script type='text/javascript'>alert('你已经订购了此商品!');window.location.href='index.html';</script>");
------解决方案--------------------
大哥你都window.close()就关闭了这个窗口了
------解决方案--------------------
探讨

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

------解决方案--------------------
你这样写是没错的,你看看与浏览器有关吗?试试IE,或者是其他的问题
------解决方案--------------------
探讨
大哥你都window.close()就关闭了这个窗口了

------解决方案--------------------
探讨

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

------解决方案--------------------
新建个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>