This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes JSP and the fly likes delete files in JSP >>>>>>>>>>>>>>>>> Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "delete files in JSP >>>>>>>>>>>>>>>>>" Watch "delete files in JSP >>>>>>>>>>>>>>>>>" New topic
Author

delete files in JSP >>>>>>>>>>>>>>>>>

verduka fox
Ranch Hand

Joined: Jan 18, 2001
Posts: 178
I am using a third party package to dynamically generate graphs which are then displayed inside my jsp. The graphing tool creates the graph as a file. We need to delete these graphs after they have been displayed. I tried doing so, but when I run the following code, my jsp does not display the graph; it just displays the box indicating an image belongs there.
. . .
<%
// generate the graph and store it to /graphs directory
%>
<img src="/graphs/graph.gif">
<%
File deleteFile = "/graphs/graph.gif";
if (deleteFile.exists())
{
deleteFile.delete();
}
%>
. . .
Can someone verify my theory here? I believe the graph is not displaying because the java code inside a scriplet in a JSP executes before the HTML is rendered to the browser. Therefore, the file is created and deleted before the <img src=". . ."> is executed in HTML.
If someone could please verify this, and if you have any ideas how to do this, I'd appreciate it. Right now, I'm guessing our only option is to run a script each night to delete the contents of the /graphs directory.
Thanks in advance.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15958
    
  19

You don't "execute" HTML tags like < img > - the page is sent to the client and the client then sends back requests to retrieve the < img >'s and other linked objects. So yes, the file is LONG gone!


Customer surveys are for companies who didn't pay proper attention to begin with.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: delete files in JSP >>>>>>>>>>>>>>>>>
 
Similar Threads
Retrieving pixel data
JSP page not displaying the image
regarding images as buttons in the form
cant display gif/jpeg in JEditorPane ?
images