Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem in Java Mail using Servlet

 
Harsh Sahajwani
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am using an html form to be filled in and a servlet to get parameters from the html form. The servlet then uses the Java Mail API to attach the file and send the mail.

The problem I am facing is that when I deploy the application on server on my local machine, the servlet gets the file location from html form, searches it on my local machine, attaches it with mail and sends it. But when I use a server installed and running on different machine on network, the servlet gets the file name from the html form, searches that file on the machine on which server is running (and not on my local machine), and fails to attach the file, and mail sending gets failed. Is there any solution to my problem? The servlet code that I am using is as follows:

Thanks,

Harsh

[BSouther: Added UBB CODE tags]
[ December 22, 2006: Message edited by: Ben Souther ]
 
Ulf Dittmer
Rancher
Pie
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch.

The server won't be able to access a file on the client directly. Instead of entering the name of the file, use a file upload element in the HTML form. Then you can use the Commons FileUpload to extract the file contents from the other form data.
 
pawank gupta
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
set your form attribute ENCTYPE="multipart/form-data", and then in servlet download your file to local machine and then send it as attachement.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by pawank gupta:
set your form attribute ENCTYPE="multipart/form-data", and then in servlet download your file to local machine and then send it as attachement.


Just changing the enctype of the form is not enough.
Servlets (out of the box) can't handle multipart form data.
This is why Ulf posted the link to commons/fileupload.
 
Talha-bin -Shakir
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
[hi-jack removed]
[ December 22, 2006: Message edited by: Ben Souther ]
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Talha-bin -Shakir,

Please do not hi-jack other people's threads.
If you have a question, start your own.

Thank you,
-Ben
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic