form with an 'attach file' feature - HOW?
I have an html form that goes to a 'Confirm' servlet (spits out an html page so the user can look over their selections before submitting), then this page calls the final servlet that e-mails the form data to a specific e-mail address.
i need to implement an 'attach file' feature, so that when the form data is e-mailed the file that was selected as an attachment gets sent along with it.
i know i am supossed to use 'input type=file' on the client-side. My question is what do i need to add to my servlets in order to send this file with the form data?
i have been searching for the answer for a few days, but can't find anything that i can use.
if anyone could help, i'd greatly appreciate it!
you cannot do this.. if there was some magical ode that you could whack into a browser, that would email a file of your choosing to a destination of your choosing, it would be one of the biggest security loopholes ever.
Unless, i have misunderstood you
i might not have been clear.
i meant is there code i could insert into my servlet that would accomplish this.
so basically i have an html form that gets processed by a servlet. i want the user to be able to attach a file from their computer to the submitted form data, so that when the form data is sent to the intended receipient, the attached file comes as an attachment in the email. i would hard-code the specific e-mail in the servlet.
i.e. form data in the BODY of the e-mail (i know how to do this) and a document, like Word, sent as the attachment.
I think you might have had more luck posting this in the J2EE/Web Services forum.
But since I was passing, an Applet sounds like the it'd do all the hard work for you.
javax.swing.JFileChooser would get the path to a file, but you'd need to 'request' access to the users hard drive (a method or two of the Applet's) for the Applet to get at the file, then you could 'pass' the file to a directory at your chosen server.
The end user would have to agree to a web page accessing their hard drive, and they'd have to select the file you know. You cant just go uploading sensitive material from a users computer.
Thanks a lot for the heads up!
i'll try and find some info on javax.swing.JFileChooser .
The simplest way would be to tell the user:
"If you want to attach a file to your post, drag and drop it onto the email window that shows when you press OK"
and show it in an OK button
trust me.. theres no way that you can place any html on a page in any way (and thats the only way a servlet can communicate with a user, via html) that will cause a file to be arbitrarily attached to an email message and sent somewhere: security. risk.
the applet solution is a bit of a numb one, because of the security restrictions applets are subject to by default, combined with the fact that applets dont run on all systems..
tbh, the answer is staring you in the face.. literally.. choose reply to this thread and look at the html that generates the "Attach file:
Maximum size: 102400 bytes" table entry..
no, you cannot email this. it must be submitted by the web browser
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center