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

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は、ディレクトリ上のファイルを削除し、メッセージを表示します。そのメッセージをウィンドウと同時にメッセージボックスに表示したい来てはいけません。

別の jsp を使用するために、javascript 関数にすべての削除コードを追加するのは好きではありません。ウィンドウを非表示にして、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 に答える