1

我试过的是

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();     
                    }

删除.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 页面中显示确认消息框。我需要一些帮助。

谢谢

4

1 回答 1

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>
于 2013-04-04T12:45:35.340 回答