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

  • Home
  • SEARCH
  • 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 6146165
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T18:54:32+00:00 2026-05-23T18:54:32+00:00

I’m building an application using jsp’s, servlets, and all that fun stuff. Right now,

  • 0

I’m building an application using jsp’s, servlets, and all that fun stuff. Right now, I have a form that passes through all the information from the form to an html email that is sent using the JavaMail API. It works, but I am trying to send an attachment, and the way I have it set up right now does not work…

<div class="section">Upload Files: <input id="fileUpload" type="file" /></div>

I take this input’s value, pass it through to my servlet and try to send the email. The problem is that when the file is sending, the servlet cannot locate the file because this tag gives it the path

C:\fakepath\file.doc

Any help would be amazing.

  • 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-05-23T18:54:33+00:00Added an answer on May 23, 2026 at 6:54 pm

    I figured it out. The fakepath was a security feature in browsers. What happens though with tomcat is that the file is actually stored in a temp folder inside the tomcat folder. So i just had to play with a tomcat library, commons.fileupload, and i used that to pull the data from the file, regardless of the fakepath location.

    //Handle File Upload for the attachment
               ServletFileUpload servletFileUpload = new ServletFileUpload(new DiskFileItemFactory());
    
                try{
                List fileItemsList = servletFileUpload.parseRequest(request);
    
                //TODO: Take datafile input from the field and pass the file name so that we can view the file name
    
                Iterator it = fileItemsList.iterator();
                while (it.hasNext()){
                  FileItem fileItem = (FileItem)it.next();
                  if (fileItem.isFormField()){
                    /* The file item contains a simple name-value pair of a form field */
                  }
                  else{ //do what you want with the file}
    

    I then passed it through to my mail utility, changed the name of the file to the correct name to have the correct extension, and it worked. Of course, you have to encode the form as a multipart form, and you have to make the Mime Message multipart as well. But its fairly simple after all that.

        MimeBodyPart textPart = new MimeBodyPart();
        textPart.setContent(body, "text/html");
    
    
    
        MimeBodyPart attachFilePart = new MimeBodyPart();
        FileDataSource fds = 
            new FileDataSource(file);
        attachFilePart.setDataHandler(new DataHandler(fds));
        attachFilePart.setFileName(fileName);
    
    
        Multipart mp = new MimeMultipart();
        mp.addBodyPart(textPart);
        mp.addBodyPart(attachFilePart);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

this is what i have right now Drawing an RSS feed into the php,
I have a text area in my form which accepts all possible characters from
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a jquery bug and I've been looking for hours now, I can't
I have a French site that I want to parse, but am running into
We're building an app, our first using Rails 3, and we're having to build
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have thousands of HTML files to process using Groovy/Java and I need to
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and

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.