Code in the SSH framework:
Public String deleRubbishAd (){
Int deleADcount = 0;
RubbishADtp = configDao. rubbishADtp (); // ad image set in the database
Map <Object, Object> shujuku = new HashMap <Object, Object> ();
File adfile = new File ("C: // Program Files // Apache Software Foundation // Tomcat 6.0 // webapps // plpwmanagers // yesilovepjustdoit2014 // AdImg ");
String adarray [];
Adarray = adfile. list (); // The ad Image array on the server. Due to the IE storage mechanism, all files obtained from the server contain a Thumbs. the thumbnail file of the db, which does not need to be processed here
// Put the advertisement image of the database into the map
For (Object shujukuad: rubbishADtp ){
Shujuku. put (shujukuad, shujukuad );
}
List <Object> diffentTp = new ArrayList <Object> (); // stores different images.
// Cyclically determine which images on the server are not in the database
For (String fuwuqi: adarray ){
If (shujuku. containsKey (fuwuqi) = false ){
DiffentTp. add (fuwuqi );
}
}
// Cyclically Delete different images
For (int I = 0; I <diffentTp. size ()-1; I ++) {// Thumbs. db file does not need to be processed
// Find the difference image on the server
File filead = new File (ServletActionContext. getServletContext (). getRealPath ("yesilovepjustdoit2014/AdImg") + "/" + diffentTp. get (I ));
Filead. delete ();
DeleADcount ++; // records the number of different images deleted
}
RubbADmap. put ("lajiadcount", diffentTp. size ()-1 );
RubbADmap. put ("deleadcounts", deleADcount );
Return "delerubbishADsuc"; // The number of junk images is returned, and the number of images is deleted.
}