aspose file tools*
The moose likes Servlets and the fly likes Converting a Java app to a Servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Converting a Java app to a Servlet" Watch "Converting a Java app to a Servlet" New topic
Author

Converting a Java app to a Servlet

David Whyte
Greenhorn

Joined: Apr 29, 2004
Posts: 1
Hi,
I'm new to Java & I have the following java app (below) which I need to deploy on a Tomcat server and call automatically from a JSP prior to writing files from a database. The app basically deletes all files of a certain extension and thus prevents old data from clogging up the server.
Therefore 2 questions:
1.) In order for this to work, how must I implement it as a server-side app?
2.) How can I invoke it automatically each time a user wants to write a file from the database? (I already have auto-reloading activated in Tomcat).

public class delfile {
public static void main (String args[]) {
delfile td = new delfile();
td.deleteFiles("C:/Tomcat/jakarta-tomcat-5.0.18/webapps/ROOT/", ".xml");
}
public void deleteFiles( String d, String e ) {
ExtensionFilter filter = new ExtensionFilter(e);
File dir = new File(d);
String[] list = dir.list(filter);
File file;
if (list.length == 0) return;
for (int i = 0; i < list.length; i++) {
file = new File(d + list[i]);
boolean isdeleted = file.delete();
System.out.print(file);
System.out.println( " deleted " + isdeleted);
}
}
class ExtensionFilter implements FilenameFilter {
private String extension;
public ExtensionFilter( String extension ) {
this.extension = extension;
}
public boolean accept(File dir, String name) {
return (name.endsWith(extension));
}
}
}

Thanks,
David
[ April 29, 2004: Message edited by: David Whyte ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Converting a Java app to a Servlet