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 java.io.FileNotFoundException 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 "java.io.FileNotFoundException" Watch "java.io.FileNotFoundException" New topic
Author

java.io.FileNotFoundException

Azz Romaysa
Ranch Hand

Joined: Dec 08, 2004
Posts: 66
Hi,

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:
Mailer.java



Ans I call this method from my servlet
OfferController.java


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

My structure:
|
|-WEB-INF
|-vrijblijvend_offerte.jsp
|

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

Joined: Mar 22, 2000
Posts: 12761
    
    5
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
Sheriff

Joined: Dec 11, 2004
Posts: 13410

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

Both are methods of ServletContext
http://java.sun.com/j2ee/1.4/docs/api/javax/servlet/ServletContext.html


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.
 
 
subject: java.io.FileNotFoundException
 
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.