在线等:jsp+javabean实现数据的增删改查,怎样在jsp进行修改或者删除操作完毕之后弹出确认提示框?
delete.jsp:
<%@ page language= "java " contentType= "text/html; charset=gb2312 "%>
<%@page import= "dao.StudentsDao " %>
<html>
<head>
<title> Delete </title>
</head>
<body>
<jsp:useBean id= "sd " scope= "page " class= "dao.StudentsDao "> </jsp:useBean>
<%sd.delete(request.getParameter( "id ")); %> //1
<jsp:forward page= "view.jsp "> </jsp:forward>
</body>
</html>
http://localhost:8080/test/delete.jsp?id=19
请问删除操作//1完成之后,应该在哪里,怎样弹出“删除成功!”的提示框?
大家都是怎么做的?
------解决方案-------------------- <body>
<jsp:useBean id= "sd " scope= "page " class= "dao.StudentsDao "> </jsp:useBean>
<%int result=sd.delete(request.getParameter( "id ")); %>
<script type= "text/javascript ">
var result= <%=result%> ;
if(result==1){
alert( '删除成功 ');
}else{
alert( '删除失败 ');
}
window.location= 'view.jsp ';
</script>
</body>
------------------------------------------------------
我做的网站(www.ju1ju.net)聚会策划助手
有时间帮我测试一下,非常感谢!
特点:自动通过邮件/手机短信/msn/qq联系朋友
架构:webwork2 spring ibatis tomcat5.5 mysql ajax javascript
------解决方案--------------------用HIBERANTE的拦截机制拦一下.
------解决方案--------------------js做最为简单..
if(删除成功)
<script>
alert( "success ");
</script>
else
<script>
alert( "fail ");
</script>
------解决方案--------------------可以再调用一个javabean操作数据库来判断,是否删除成功,如果成功则out.print( "sucess "),反之则out.print( "flaut ")
------解决方案--------------------out.println( " <script> alert( '删除成功 ') </script> ");
------解决方案--------------------用javascript
------解决方案-------------------- <body>
<jsp:useBean id= "sd " scope= "page " class= "dao.StudentsDao "> </jsp:useBean>
<%boolean flag = sd.delete(request.getParameter( "id ")); %>
<%if(flag){%>
<script type= "text/javascript ">
alert( "删除成功! ");
</script>
<%}else{ %>
<script type= "text/javascript ">
alert( "删除失败! ");
</script>
<%} %>
<jsp:forward page= "viewStudents.jsp "> </jsp:forward>
</body>
怎么这样还是没有弹出框呢?
在解释后的HTML代码到达浏览器之后,已经被forward掉了,根本不可能弹得出框框来。
可以改为以下试试:
<body>
<jsp:useBean id= "sd " scope= "page " class= "dao.StudentsDao "> </jsp:useBean>
<%boolean flag = sd.delete(request.getParameter( "id ")); %>
<%if(flag){%>
<script type= "text/javascript ">
alert( "删除成功! ");