Win a copy of Java EE 8 High Performance this week in the Java/Jakarta EE forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Converting a Java app to a Servlet  RSS feed

Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.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));

[ April 29, 2004: Message edited by: David Whyte ]
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!