我试过的是
First.jsp
<form name = "button" style="VISIBILITY: visible">
<table cellspacing=5 cellpadding=5 bgcolor="lightblue" colspan=2 rowspan=2 align="center">
<TR> <TD> <INPUT TYPE="button" onclick="sub1();hide();" VALUE="DOWNLOAD"></TD>
<script>
function popup()
{
popupWindow = window.open('delete','name','width=300,height=100');
popupWindow.focus();
window.close();
}
delete.jsp
<%
String Pdfpath= session.getAttribute("pdfpath").toString();
File f =new File(Pdfpath);
Boolean flag=false;
if(f.exists())
{
flag=f.delete();
}
else
{
out.println("File not found to delete");
}
%>
<html>
<head>
<title>Delete file in java</title>
</head>
<body>
<%
if(flag==true)
{
out.println("File Has Bean deleted successfully");
}
else
{
out.println("Error: Unable To Delete The File");
}
%>
</body>
</html>
从我的第一个jsp我将一些路径传递给另一个delete.jsp按钮点击。这个jsp删除我目录中的文件并发出消息。我希望该消息来自同一个消息框中窗口不应该来的时间。
我不喜欢在javascript函数中添加所有删除代码,所以我要去另一个jsp。是否可以隐藏窗口并在delete.jsp页面中仅显示确认消息框。我需要一些帮助。
由于
答案 0 :(得分:1)
您可以使用以下代码作为delete.jsp;)
<%
String Pdfpath = session.getAttribute("pdfpath").toString();
File f = new File(Pdfpath);
Boolean flag = false;
if (f.exists()) {
flag = f.delete();
} else {
out.println("File not found to delete");
}
%>
<html>
<head>
<title>Delete file in java</title>
</head>
<body>
<%
String message = "";
if (flag == true) {
message = "File Has Bean deleted successfully";
} else {
message = "Error: Unable To Delete The File";
}
%>
<script type="text/javascript">
alert('<%=message%>');
</script>
</body>
</html>