2013-04-04 41 views
1

我已經試過是如何添加消息框,而不是新的窗口,在JSP

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我傳遞到另一個刪除一些路徑。 jsp的按鈕click.That jsp刪除我的目錄上的文件,並給出一條消息。我希望該消息來自消息框,同時該窗口不應該來。

我不喜歡在javascript函數中添加所有的刪除代碼,以便我要換另一個jsp。是否可以隱藏窗口並在delete.jsp頁面中只顯示確認消息框。我需要一些幫助。

感謝

+0

使用JSTL和EL,就像你可以:) – kayz1 2013-04-04 12:48:31

回答

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> 
+0

新的窗口仍然there.Is有辦法隱藏那個窗口? – 2013-04-04 12:49:33

+0

你是什麼意思的新窗口?你的意思是delete.jsp? – 2013-04-04 17:10:43

+0

是............. – 2013-04-05 04:46:56

相關問題