每当我尝试从Web浏览器中的HTML页面(Google chrome或Mozzila)附加任何文件并将其发送到Servlet时,我只会得到文件名而没有完整的路径。如果我从C驱动器添加了任何文件的附件,则无法获取其完整地址。每当我尝试将此文件名发送到邮件服务器时,都会遇到异常:

Caused by: java.io.FileNotFoundException: Hello.txt (The system cannot find the file specified)
    at java.io.FileInputStream.open(Native Method)
    at java.io.FileInputStream.<init>(Unknown Source)
    at javax.activation.FileDataSource.getInputStream(Unknown Source)
    at javax.activation.DataHandler.writeTo(Unknown Source)
    at javax.mail.internet.MimeBodyPart.writeTo(MimeBodyPart.java:1381)
    at javax.mail.internet.MimeBodyPart.writeTo(MimeBodyPart.java:852)
    at javax.mail.internet.MimeMultipart.writeTo(MimeMultipart.java:452)
    at com.sun.mail.handlers.multipart_mixed.writeTo(multipart_mixed.java:98)
    at javax.activation.ObjectDataContentHandler.writeTo(Unknown Source)
    at javax.activation.DataHandler.writeTo(Unknown Source)
    at javax.mail.internet.MimeBodyPart.writeTo(MimeBodyPart.java:1381)
    at javax.mail.internet.MimeMessage.writeTo(MimeMessage.java:1742)
    at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:737)
    ... 18 more


我如何摆脱这个问题?如何获取我上传的文件的完整地址?

最佳答案

即使您要获取完整路径,它也将是服务器无法访问的客户端计算机上文件的路径。

如果要将上载的文件存储在服务器上,则需要将上载的文件存储在本地服务器文件系统上,然后将其传递给JavaMail API。

关于java - 附件没有完整的路径名,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/1679048/

10-16 17:40