2013-04-04 22 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

相关问题