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
Marshal
Joined: Mar 22, 2005
Posts: 35252
7
posted
0
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.
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.