Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9150655
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T11:38:25+00:00 2026-06-17T11:38:25+00:00

I have been searching this topic for quite a while, and haven’t found anything

  • 0

I have been searching this topic for quite a while, and haven’t found anything that has been able to solve my problem.. so I turn to you!

I have a JSP where I open a file dialog box to select a file. Previously, I used this to upload the file to a specified directory (in my code). This works fine. I am now trying to use the same code to delete that same file by selecting it in the appropriate directory and passing it off to the servlet, which I included below. I am using the Apache Common FileUpload library to do this.

protected void doPost(HttpServletRequest request,
        HttpServletResponse response) throws ServletException, IOException {
    // checks if the request actually contains upload file
    if (!ServletFileUpload.isMultipartContent(request)) {
        // if not, we stop here
        return;
    }

    // configures some settings
    DiskFileItemFactory factory = new DiskFileItemFactory();

    ServletFileUpload delete = new ServletFileUpload(factory);

    // constructs the directory path to delete file
    String deletePath = UPLOAD_DIRECTORY;

    // parses the request's content to extract file data
    List formItems = delete.parseRequest(request);
    Iterator iter = formItems.iterator();

    // iterates over form's fields
    while (iter.hasNext()) {
        FileItem item = (FileItem) iter.next();


        // processes only fields that are not form fields
        if (!item.isFormField()) {


            String fileName = new File(item.getName()).getName();
            String filePath = deletePath + File.separator + fileName;
            File storeFile = new File(filePath);

            //File storeFile = new File("C:\\temp\\discLogo.txt");

            // deletes the file on disk
            boolean erased = storeFile.delete();
            }
        }

UPLOAD_DIRECTORY is where I am storing my files from my upload JSP. The delete method works fine if I uncomment the line I commented out for storeFile with the hardcoded directory, as long as I select a DIFFERENT FILE in the directory initially. This leads me to believe the HttpServletRequest is holding the file in memory somewhere.

Is this correct? is there any way I can release it so I can delete the file I select initially? Or is there a much simpler way to do this?

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T11:38:25+00:00Added an answer on June 17, 2026 at 11:38 am

    Looks like my issue was in my JSP. I had the following form initially:

    <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <title>File Delete</title>
    </head>
    <body>
        <form method="post" action="DeleteServlet"
            enctype="multipart/form-data">
            Select file to delete: <input type="file" name="dataFile"
                id="fileChooser" /><br />
            <br /> <input type="submit" value="Delete" />
        </form>
    </body>
    </html>
    

    I changed this by deleting encytype="multipart/form-data" from the form, and was then able to use request.getParameter(“dataFile”) to get the file name.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been searching in a lot of topics but I haven't found anything
I know that this a very common topic and I have been searching for
I have been searching this for quite a while but couldn't find a solution
I have been searching for a solution to this and so far found nothing
I have been searching for this solution for some time have not found any
I have been searching around for a solution to this for a while. I'm
I know this is a popular topic, but I've been searching quite a bit
I've been searching for a while on the topic but found nothing at all.
I have been searching this since yesterday and still nothing. From all that researching
I've been doing quite a bit of searching, but haven't been able to find

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.