sql 命令执行后如何触发警报?
How to fire alert after sql command executed?
我需要在执行 sql 语句后成功添加产品后收到警报
我试过了,但是添加成功后没有提示信息
<%@include file="connection.jsp" %>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<%
String dbpname = request.getParameter("pname");
String dbpid = request.getParameter("pid");
String dbptype = request.getParameter("ptype");
String dbaddress = request.getParameter("address");
String dbaddress1 = request.getParameter("address1");
String dbpquat = request.getParameter("pquat");
String dbpcost = request.getParameter("pcost");
PreparedStatement ps=conn.prepareStatement("insert into PRODUCT values(?,?,?,?,?,?,?,0,0)");
ps.setString(1,dbpname);
ps.setString(2,dbpid);
ps.setString(3,dbptype);
ps.setString(4,dbaddress);
ps.setString(5,dbaddress1);
ps.setString(6,dbpquat);
ps.setString(7,dbpcost);
int i=ps.executeUpdate();
if(i!=0)
{
{ %>
<script> alert("added sucessfully");</script>; <%
response.sendRedirect("AddProducts.jsp");}
%>
</body>
</html>
问题是 jsp 执行 SQL 更新后,它重定向到 AddProducts.jsp。这就是警报永远不会显示在浏览器中的方式。您使用浏览器 http 跟踪来测试它。要修复它,您可以在警报显示后删除 response.sendRedirect 并执行 JavaScript 重定向( window.location = url;
)。
替换代码块:
警报("added sucessfully");; <%
response.sendRedirect("AddProducts.jsp");}
%>
与:
<script>
alert("added sucessfully");
window.location = "AddProducts.jsp";
</script>
我需要在执行 sql 语句后成功添加产品后收到警报
我试过了,但是添加成功后没有提示信息
<%@include file="connection.jsp" %>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<%
String dbpname = request.getParameter("pname");
String dbpid = request.getParameter("pid");
String dbptype = request.getParameter("ptype");
String dbaddress = request.getParameter("address");
String dbaddress1 = request.getParameter("address1");
String dbpquat = request.getParameter("pquat");
String dbpcost = request.getParameter("pcost");
PreparedStatement ps=conn.prepareStatement("insert into PRODUCT values(?,?,?,?,?,?,?,0,0)");
ps.setString(1,dbpname);
ps.setString(2,dbpid);
ps.setString(3,dbptype);
ps.setString(4,dbaddress);
ps.setString(5,dbaddress1);
ps.setString(6,dbpquat);
ps.setString(7,dbpcost);
int i=ps.executeUpdate();
if(i!=0)
{
{ %>
<script> alert("added sucessfully");</script>; <%
response.sendRedirect("AddProducts.jsp");}
%>
</body>
</html>
问题是 jsp 执行 SQL 更新后,它重定向到 AddProducts.jsp。这就是警报永远不会显示在浏览器中的方式。您使用浏览器 http 跟踪来测试它。要修复它,您可以在警报显示后删除 response.sendRedirect 并执行 JavaScript 重定向( window.location = url;
)。
替换代码块:
警报("added sucessfully");; <%
response.sendRedirect("AddProducts.jsp");}
%>
与:
<script>
alert("added sucessfully");
window.location = "AddProducts.jsp";
</script>