Hi I wrote the below Java code to email a file as attachement. It works fine if I provide a sample filepath. But, I want it to take the file path browsed by the user in the Front End
//code to attach the file
MimeBodyPart messageBodyPart = new MimeBodyPart();
Multipart multipart = new MimeMultipart();
messageBodyPart.setText(sb.toString());
MimeBodyPart messageBodyPart2 = new MimeBodyPart();
//String filename = filePath;
String filename = "C:/Users/S.Mandava/Documents/ContactusAction.java";
DataSource source = new FileDataSource(filename);
messageBodyPart2.setDataHandler(new DataHandler(source));
messageBodyPart2.setFileName(filename);
multipart.addBodyPart(messageBodyPart);
multipart.addBodyPart(messageBodyPart2);
msg.setContent(multipart);
System.out.println("Attaching the file");
Transport.send(msg);
Form example, I want the system to take the file path uploaded in the below form when the user clicks on submit and the file should be sent as an attachment in an email
<form >
<input type ="file"/ id="multiple_files" name="multiple_files" multiple><br/>
<button>Submit</button>
</form>
How do I do it? I want to use JSP and JavaScript on the Front End and Java on the Back End. I am having difficulty in getting the file path.