form with an 'attach file' feature - HOW?


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 6 of 6

Thread: form with an 'attach file' feature - HOW?

  1. #1
    Join Date
    Mar 2004
    Posts
    3

    form with an 'attach file' feature - HOW?

    hi!

    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!

    THANKS!!!!

  2. #2
    Join Date
    Feb 2004
    Posts
    808
    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
    The 6th edict:
    "A thing of reference thing can hold either a null thing or a thing to any thing whose thing is assignment compatible with the thing of the thing" - ArchAngel, www.dictionary.com et al.
    JAR tutorial GridBag tutorial Inherited Shapes Inheritance? String.split(); FTP?

  3. #3
    Join Date
    Mar 2004
    Posts
    3
    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.

    THANKS!!!

  4. #4
    Join Date
    Jan 2004
    Posts
    20
    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.

    Cheers, DJDaveMark

  5. #5
    Join Date
    Mar 2004
    Posts
    3
    Thanks a lot for the heads up!

    i'll try and find some info on javax.swing.JFileChooser .

  6. #6
    Join Date
    Feb 2004
    Posts
    808
    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
    The 6th edict:
    "A thing of reference thing can hold either a null thing or a thing to any thing whose thing is assignment compatible with the thing of the thing" - ArchAngel, www.dictionary.com et al.
    JAR tutorial GridBag tutorial Inherited Shapes Inheritance? String.split(); FTP?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center