File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes FileNotFoundException Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "FileNotFoundException" Watch "FileNotFoundException" New topic


Erick Martin

Joined: May 17, 2002
Posts: 8
Hi everybody, the following class <URLMappingsXmlDAO> it is supposed to print out all the elements of <whatever.xml> file for testing purposes. It is invoked from a servlet <MyServlet>
<MyServlet> is sitting @ WEB-INF/classes/com/mydomain/controller/
<URLMappingsXmlDAO> @ WEB-INF/classes/com/mydomain/controller/web/
<whatever.xml> @ WEB-INF/
I keep getting a FileNotFoundException, for some reason it cannot find the xml file.
Any suggestions? Thanks in advance,

package com.mydomain.controller.web;
import org.xml.sax.XMLReader;
import org.xml.sax.Attributes;
import org.xml.sax.InputSource;
import org.xml.sax.helpers.XMLReaderFactory;
import org.xml.sax.helpers.DefaultHandler;
import org.xml.sax.SAXException;
import org.apache.xerces.parsers.SAXParser;
public class URLMappingsXmlDAO extends DefaultHandler

public static void loadDocument(String location) throws SAXException, IOException {
XMLReader xr = new org.apache.xerces.parsers.SAXParser();
URLMappingsXmlDAO handler = new URLMappingsXmlDAO();
FileReader r = new FileReader(location);
xr.parse(new InputSource(r));

This is the calling servlet:
package com.mydomain.controller;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.naming.NamingException;
import javax.naming.InitialContext;
import com.mydomain.controller.web.URLMappingsXmlDAO;
public class MyServlet extends HttpServlet {
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
try {
catch (org.xml.sax.SAXException ex) {
System.err.println("SAX Driver: " + ex);
catch (IOException ex) {
System.err.println("File: " + ex);

sa<br />Sun Certified Programmer for Java 2 Platform<p>"... black holes are those places in the Universe where God attempted to divide by zero"
Riaz Mohamed

Joined: May 31, 2002
Posts: 23
have u mapped u'r servlet in web.xml
Erick Martin

Joined: May 17, 2002
Posts: 8
The deployment descriptor has the required mapping for the servlet. As you can see the FileNotFoundException is being caught within the servlet.
When the mappings r not ok, you get a different kind of error, like "resource not available" or something like that.
Any other ideas anyone? Thanks,
[ June 07, 2002: Message edited by: Erick Martin ]
I agree. Here's the link:
subject: FileNotFoundException
It's not a secret anymore!