Can I delete a file in my web folder using JSP/servlet?

I want to delete some of the files in my website. How can I give file path. I have uploaded my website in US. Just by uploading a servlet /jsp I want to delete files in my directory.
Is it possible to delete files using Servlert/jsp. What path should I give for the file name in jsp/servelet?

It is possible. You can just specify the absolute file path in a File object and then invoke the delete() method. File file = new File("/path/file.ext");
file.delete();See the File API [1] for details. Further on I think that you also want to know how to get the absolute file path for the given relative path. If so, it's available by ServletContext#getRealPath() [2]. To get for example the absolute root path, just query the relative root path "/":
String rootPath = getServletContext().getRealPath("/");[1] http://java.sun.com/j2se/1.5.0/docs/api/java/io/File.html
[2] http://java.sun.com/javaee/5/docs/api/javax/servlet/ServletContext.html

Similar Messages

  • Any good books on web application using JSP/servlet?

    Does anyone know good books on how-to build enterprise web application using JSP/servlet? Aside from the book "Head First JSP/Servlet". Development using Netbeans is more preferrable.

    801264 wrote:
    What about the free web server? JBoss or Glassfish or something else? I prefer web/application server that is fully compatible with JEE6 (unlike Tomcat that can't handle EJB). thanksI'm a JBoss user myself, so naturally I would advise that to you if I were ignorant. I'm not however, so in stead I'll tell you to investigate yourself and see which one you prefer. Nobody is going to tell you which one to use as there is no such thing as a 'better' or 'best' server. Just different servers each with different issues.
    And the community edition of JBoss has had many issues in the past (because Red Hat of course wants to advise you to go to the enterprise platform which ain't cheap), but JBoss 5.1 was a rock solid piece of software that I have had zero problems with (after reading the odd forum or two). JBoss 6 builds on top of JBoss 5.1 and provides the full JEE6 web profile; this means it does NOT provide a certified 'full' JEE6 stack yet. This means nothing however as all the services you may need in an enterprise application are already there.
    BTW: for simple servlet programming, don't neglect Apache Tomcat. Its a lightweight server that just works.

  • I can't delete the files in my spam folder

    Spam email is existing in the spam folder. I can usually delete them. I click the box next to the spam items ad hit delete. Nothing happens. Is there a setting that has been changed?

    Sorry, Firefox doesn't have a spam folder. Please see your webmail service provider for help with that issue.

  • How to open a pdf file in a web browser using jsp

    Hi,
    I have a problem opening pdf file in browser using jsp.the following is my code.Can anyone help me.Thanks
    response.setContentType("application/pdf");
    String filename="C:\\FictPos\\mypdf.pdf";
    File file = new File(filename);
    FileInputStream in = new FileInputStream(file);
    OutputStream out1=response.getOutputStream();
    byte[] buf = new byte[4096];
    int count = 0;
    while ((count = in.read(buf)) >= 0)
    out1.write(buf, 0, count);
    in.close();
    out1.close();
    }

    Don't know the problem specifically, but here are some suggestions to investigate:
    Does it show anything in the page when you view source on it?
    I would recommend using a servlet rather than a JSP page for this, if only for the fact the JSPs can insert carriage returns into places where you might not want them to. This might screw up the PDF file format?
    Try setting the a link to the jsp, right-click and "save target as..." just to see if it gets any response at all - ie bypass the browser display.
    Good luck,
    evnafets

  • Can't Delete A File (because it is in use)

    I'm in the process of transferring a bunch of files from my iMac to an external HD. Last night, in the middle of transferring files, my computer suddenly and without warning shut off (a whole 'nother issue). The file transfer did not complete and I now have a grayed-out file folder that cannot be opened. When I try to drag it to the trashcan, or even right-click and select "Move to Trash", I get the following error: "The operation can’t be completed because the item “DSC_5594-Edit.psd” is in use." I've searched the Web for a solution but haven't come across anything that works. I've tried rebooting in normal mode, rebooting in safe mode, used " rm -rf " command in Terminal, and even downloaded "What's Keeping Me?" to find the process using the file, but the app wasn't able to find the file.
    I'm hoping that somebody here will be able to help me with this perplexing situation before I pull out what little hair I have left!
    Thanks!
     Chris

    chattphotos wrote:
    Did you use sudo rm -Rf on the problem folder?
    What was the error when you tried rm -rf?
    Yes, I tried with and without sudo;
    Without sudo:
    christophersimac:~ chris$ rm -rf /Volumes/Public/_Chris/Pictures\ 2/2013/08
    rm: /Volumes/Public/_Chris/Pictures 2/2013/08/13/DSC_5594-Edit.psd: Resource busy
    rm: /Volumes/Public/_Chris/Pictures 2/2013/08/13: Directory not empty
    rm: /Volumes/Public/_Chris/Pictures 2/2013/08: Directory not empty
    With sudo:
    christophersimac:~ chris$ sudo rm -rf /Volumes/Public/_Chris/Pictures\ 2/2013/08 
    WARNING: Improper use of the sudo command could lead to data loss
    or the deletion of important system files. Please double-check your
    typing when using sudo. Type "man sudo" for more information.
    To proceed, enter your password, or type Ctrl-C to abort.
    Password:
    rm: /Volumes/Public/_Chris/Pictures 2/2013/08/13/DSC_5594-Edit.psd: Resource busy
    rm: /Volumes/Public/_Chris/Pictures 2/2013/08/13: Directory not empty
    rm: /Volumes/Public/_Chris/Pictures 2/2013/08: Directory not empty

  • Can't delete .ai files

    I can't delete .ai files in Adobe Illustrator v.10 in running on Vista.
    error says "....can't delete file is begining used"
    I have tried everything the web has to offer including:  safe boot, various deletion software, changing aiicon.dll, Crap cleaner, chsdsk, etc.
    I sure there are plenty of people that have this problem, as I scan the web, however, no solutions have seem to be found.
    Please help!!

    I've had this problem frequently with both .AI and .EPS files on Windows XP, from different versions of Illustrator, notably 7 and 10. You may want to try this program:
    http://cleansofts.org/unlocker.html
    It runs quietly in the background until there is a sharing violation (e.g. you are unable to delete a file, etc.). Then it pops up a window showing which process has locked the file. With Illustrator files, the culprit is usually Windows Explorer... my guess is that it tries to generate a preview thumbnail but somehow never quite finishes, and leaves the file open. You will have the option of killing the offending process (which is kind of a dirty way to do things, but drastic times... you know). You should then be able to delete the file(s) with no problem.
    ---Peter

  • Once a movie is copied into iTunes, can I delete the file from the folder?

    I've copied several movies into iTunes and then sync'd them onto my Apple TV.
    My question is: Once I've copied a movie into iTunes, can I delete the movie from its original folder (e.g. the Movie folder) and still have the movie in my iTunes?
    More specifically, does "dragging and dropping" the movie into iTunes make a new copy of the movie file so that I can delete the original file? And if I can delete the original file, should I?
    MacBook Pro   Mac OS X (10.4.9)  

    Thanks. I'll check and see when I get home tonight. My guess is that that's the setting since my disk space has decreased a lot when I started copying things into iTunes.
    MacBook Pro Mac OS X (10.4.9)

  • I cannot delete a file from the document folder.  I can move it to the trash and then empty the trash, but when I go back to the documents folder it is still there.

    I cannot delete a file from the documents folder.  I can move it to the trash and then empty it, but when I go back to the documents folder, the file is still there.

    Gay,
    I wonder what your computing environment is. Is your account being administrated by another account? Are you working in an account subject to "Parental Controls"?
    Jerry

  • How can I delete a file from Adobe Acrobat Reader DC?

    How can I delete a file from Adobe Acrobat Reader DC?

    What operating system do you use? Where do you store the files?

  • How can I delete PDF files from my iMac desktop?

    How can I delete PDF files from my iMac desktop?

    Not on my system,When I try to dump if off in the trash it will not go. I get a message that says this file cannot be removed. I also tried going to File and clicking on Move to Trash. No dice.

  • How can I delete the files .DS_store in Mac OS Yosemite?

    How can I delete the files .DS_store in Mac OS Yosemite?

    The .DS_Store file is normal. It holds certain settings related to the folder it is found in. Removing these files is futile, as they will come back, as you have observed.
    If you are seeing them on your Mac, that means you have changed settings so that your Mac is showing invisible files in the Finder. To reverse that, run the following command in the Terminal:
    defaults write com.apple.finder AppleShowAllFiles NO
    This will hide them, and any other invisible files, from view.
    If you are seeing them on a Windows machine, just ignore them. They're not doing any harm.
    If you found a Terminal command that is supposed to stop them from being created, I would be extremely skeptical as to the wisdom of running it.

  • Time capsule intern.1TB hard drive.How can I delete all files

    Hello How can I delete all files from my timecapsule.
    I have connectet it with Wifi or ethernet. It is not possible.
    I have made a reset.
    I have tried it often.
    Please help
    Greetings from Vienna
    Pepimeier

    If you open Macintosh HD > Applications > Utiltiies > AirPort Utility and click Manual Setup, are you able to access the settings for the Time Capsule?
    Or, does AirPort Utility scan for the Time Capsule and then not find it?

  • Can i delete ALL files in directory ?

    i create a upload test using FileReference & PHP.
    In this scenario user upload files to http server.
    Now how can i delete all files in /files/uploads folder in AS3
    AS3 Code:
    req = new URLRequest();
    req.url = ( stage.loaderInfo.parameters.f )? stage.loaderInfo.parameters.f : "http://www.website.com/test/upload.php";
    uploadFile = new FileReference();
    select_btn.addEventListener( MouseEvent.CLICK, browse );
    uploadFile.addEventListener( Event.COMPLETE, complete_func );
    uploadFile.addEventListener( DataEvent.UPLOAD_COMPLETE_DATA, show_message );
    function browse( e:MouseEvent )
              filefilters = [new FileFilter('Images',"*.jpg;*.png;*.gif")];
              uploadFile.browse( filefilters );
    function complete_func( e:Event )
              trace( 'complete !' );
    function show_message(e:DataEvent)
    if (e.data == 'ok')
              label_txt.text = 'The file has been uploaded.';
    else if ( e.data == 'error')
              label_txt.text = 'The file could not be uploaded.';
    PHP Code:
    <?php
    $uploads_dir = './files/uploads';
    if( $_FILES['Filedata']['error'] == 0 ){
              if( move_uploaded_file( $_FILES['Filedata']['tmp_name'], $uploads_dir.$_FILES['Filedata']['name'] ) ){
                        echo 'ok';
                        exit();
    echo 'error';
    exit();
    ?>

    You need call another PHP file
    <?php
       $directory = './files/uploads';
       getDirectoryList ($directory);  
       //This function find all the files in the directory
       function getDirectoryList ($directory)
         // create an array to hold directory list
         $results = array();
         // create a handler for the directory
         $handler = opendir($directory);
         // open directory and walk through the filenames
         while ($file = readdir($handler)) {
           // if file isn't this directory or its parent, add it to the results
           if ($file != "." && $file != "..") {
        //$results[] = $file;
         // Delete Files
        $filename = $file;
      unlink($filename); //this delete a file
         // tidy up: close the handler
         closedir($handler);
    ?>

  • I can't delete a file in the Content-Management

    Hello,
    I can't delete a file in the Content-Management, altough I have full control.
    I get the following error message:
    System error (com.sapportals.wcm.repository.ResourceNotFoundException): null
    Many thanks for the help.

    Dear SAPMuffel ,
    As far as we can see the error "com.sapportals.wcm.repository.ResourceNotFoundException" is telling that the resource you are trying to delete could not be found, that is also to say, it might not exist any more.
    So please let me know exactly how you can reproduc this issue?
    and what kind of file it is? under what kind of KM repository? 
    Is there any other file under the same KM folder?
    Also you can reproduce the issue and then check the lastest defaulttrace file under this folder:
    ../j2ee/cluster/server0/log/defaultTrace.*.trc
    here you can find the detailed exception.
    Best Regards,
    Thunder

  • I  can't delete raw files in bridge

    I can't delete raw files in bridge anymore. I used to and it worked. Now if I click delete button, nothing happens.

    Adobe doesn't support CS5, an when I spoke to Apple, I was told that this is a known issue with OS 10.8.5 and that they're working on a patch.  In the meantime I'm using Adobe's DNG as a workaround.
    Have not heard before of this Known Issue, also find it hard to believe being true. But can't test my self because I only have CS6 and CC installed and always use Photodownloader to convert to DNG upon import. I have just installed the 10.8.5 update and checked in Bridge CC pointing to an attached card reader. no problem in showing the CR2 thumbs, it works as always and as expected.
    To my knowledge Bridge CS5 is already 64 bits and I can't think of any valid reason why an OS update would cause this problem so suddenly (but I'm not a technician I have to confess…)
    However, I would first try a check and repair permissions from Apple Disk Utility and also try Cocktail (good and cheap 3th party maintenance application for Mac) to clear caches and check permissions.
    Also try a new user account just for testing to rule out your current account as the culprit.

Maybe you are looking for

  • WHEN DOES UPDATE  HAPPEN IN JDBC SENDER Adapater

    Hi folks , I am using jdbc sender adapater to call RFC function and the o/p pf the RFC i am writing to the file This is my select query SELECT * FROM ULIDTA2.F5631505 WHERE QSINTF='N' and mu update query is Update ULIDTA2.F5631505 set QSINTF='Y' wher

  • Nano connection

    I have a 8Gb nano. The latest version of itunes has been loaded succesfully. When I connect the ipod via usb, it tries to locate and install driver software and then asks for disk. As I have no disk it checks for solution. No driver software found! A

  • How do I escalate this to someone who actually cares and can fix the problem?

    We have an ongoing problem related to our phone service, bundle, and billing that has been ongoing for months now (It's a long and complex story so I'm not going to post the details here unless it'll really help). My wife and I have repeatedly made c

  • Hi Res images in iMovie iPad.

    I need to add hi res images to a movie I'm making in imove on ipad. I have emailed it to myself, but when I'm import it into the camera roll iOS lowers the resolution. Is there a work around?

  • How to map business scenario in CS

    Hi all, My client want to implement CS , but there business is to provide repair service , not manufacturing . Eg  AC repairing service only  they are not manufacturing ACs. then how to take material in stock to repair it & deliver it to customer aft