This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Servlets and the fly likes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "" Watch "" New topic

Azz Romaysa
Ranch Hand

Joined: Dec 08, 2004
Posts: 66

I'm trting to send an attachment file using javaMail. My problem is if I set the whole path of the file (for example: C:/myFile.jsp), then it works. But not if I set a relative path.

This is the code:

Ans I call this method from my servlet

The exception that I get: \vrijblijvend_offerte.jsp (The system cannot find the path specified)

My structure:

Thank you,
[ October 22, 2005: Message edited by: Azz Romaysa ]
William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 12761
You "relative" file path usage depends on the "current" directory - something you can't control in a servlet. You can convert a relative path in a servlet context to an absolute path - see the ServletContext getRealPath method.
Ben Souther

Joined: Dec 11, 2004
Posts: 13410

There are two methods you should read up on:
getRealPath and getResourceAsStream.

Both are methods of ServletContext

Note: getRealPath has a serious drawback. If you're running your application from a packed war file getRealPath will return null.

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Azz Romaysa
Ranch Hand

Joined: Dec 08, 2004
Posts: 66
Thank you very much,
The getRealPath() has fixed the problem.
Similar Threads
java mail attachment notification
JavaMail API error
Sending mail through Exchange Server
How to send mail to more than one recipients
Cannot Call My class file from JSP.