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 76103
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T20:37:15+00:00 2026-05-10T20:37:15+00:00

This just won’t work. The problem is that I do not know enough to

  • 0

This just won’t work. The problem is that I do not know enough to even know what is supposed to happen. I can’t debug this code. I’d like to store upload to temporary folder ‘temp’ and then to move them to ‘applets’. Please help? The servlet is obviously being accessed, but I can’t find the uploaded files… Thanks in advance.

Form (which is created using a scriptlet – I put this here if that could cause problems):

<% out.write('<p>Upload a new game:</p>');                     out.write('<form name=\'uploadForm\' action=\'game.jsp\' '                     + 'method=\'POST\' enctype=\'multipart/form-data\'>'                     + '<input type=\'file\' name=\'uploadSelect\' value=\'\' width=\'20\' />'                     + '<br><input type=\'submit\' value=\'Submit\' name=\'uploadSubmitButton\' '                     + 'onclick = \'submitToServlet2('UploadGameServlet');\'>'                             + '</form>');  %> 

Which calls this javascript:

function submitToServlet2(newAction)     {        document.uploadForm.action = newAction;     } 

Which in turn goes to the servlet (code included in full, since there may be some important element hiding)

package org.project;  import java.io.*; import java.util.Iterator; import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; // import servlet stuff import org.apache.commons.fileupload.*;   public class UploadGameServlet extends HttpServlet {  /**  * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods. * @param request servlet request * @param response servlet response */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {     response.setContentType('text/html;charset=UTF-8');      if (ServletFileUpload.isMultipartContent(request))     {         try          {             // Create a factory for disk-based file items             FileItemFactory factory = new DiskFileItemFactory();              // Create a new file upload handler             ServletFileUpload upload = new ServletFileUpload(factory);              // Parse the request             List items = upload.parseRequest(request); /* FileItem */              File repositoryPath = new File('\\temp');             DiskFileItemFactory diskFileItemFactory = new DiskFileItemFactory();             diskFileItemFactory.setRepository(repositoryPath);              Iterator iter = items.iterator();             while (iter.hasNext())              {                 FileItem item = (FileItem) iter.next();                 File uploadedFile = new File('\\applets');                 item.write(uploadedFile);             }                     }         catch (FileUploadException ex)          {             Logger.getLogger(UploadGameServlet.class.getName()).log(Level.SEVERE, null, ex);         }         catch (Exception ex)          {             Logger.getLogger(UploadGameServlet.class.getName()).log(Level.SEVERE, null, ex);         }     }      PrintWriter out = response.getWriter();     try {         out.println('<html>');         out.println('<head>');         out.println('<title>Servlet UploadGameServlet</title>');           out.println('</head>');         out.println('<body>');         out.println('<h1>Servlet UploadGameServlet at ' + request.getContextPath () + '</h1>');         out.println('</body>');         out.println('</html>');     } finally {          out.close();     } }  

}

  • 1 1 Answer
  • 1 View
  • 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. 2026-05-10T20:37:16+00:00Added an answer on May 10, 2026 at 8:37 pm
    File repositoryPath = new File('\\temp'); File uploadedFile = new File('\\applets'); 

    By trying to access these files without any sort of leading or absolute path, you are trying to write to files (not directories) named temp and applets under the current working directory. In an app server, the current working directory is usually the bin folder (depends on what app server you use, etc).

    Some suggestions:

    1. Use an absolute path (preferably stored in web.xml or a properties file) to refer to the directory you want to save files to.
    2. You have to specify the name of the file you want to write to, you probably want to create some sort of random/unique name per request.
    3. Save yourself some keystrokes and use a member variable instead of all the Logger.getLogger(UploadGameServlet.class.getName()) references!
    4. Add some debugging, especially to see where you are writing your data to – log the result of repositoryPath.getAbsolutePath(), for example.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 214k
  • Answers 214k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer If the membership provider is working make sure you have… May 12, 2026 at 10:44 pm
  • Editorial Team
    Editorial Team added an answer Yes, you can do that. You can access the VBA… May 12, 2026 at 10:44 pm
  • Editorial Team
    Editorial Team added an answer All the previous replies are sound. For the copy constructor,… May 12, 2026 at 10:44 pm

Related Questions

This just won't work. The problem is that I do not know enough to
Lets say I have two separate databases, X and Y, on the same physical
I'm playing around with jetpack to change the title (and ideally the favicon) of
I have a pretty simple ASP.NET MVC Site Application. (MVC 1.0) I have NO
<?php if(isset($_POST['upload']) && $_FILES['userfile']['size'] > 0) { $dbhost = 'localhost'; $dbuser = 'zuk1_boo'; $dbpass

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.