Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
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

Converting a Java app to a Servlet

David Whyte

Joined: Apr 29, 2004
Posts: 1
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 ]
I agree. Here's the link:
subject: Converting a Java app to a Servlet
It's not a secret anymore!