Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

FileNotFoundException

 
Erick Martin
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 java.io.FileReader;
import java.io.IOException;
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();
xr.setContentHandler(handler);
xr.setErrorHandler(handler);
FileReader r = new FileReader(location);
xr.parse(new InputSource(r));
}

}
This is the calling servlet:
package com.mydomain.controller;
import java.io.*;
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 {
URLMappingsXmlDAO.loadDocument("/WEB-INF/whatever.xml");
}
catch (org.xml.sax.SAXException ex) {
System.err.println("SAX Driver: " + ex);
}
catch (IOException ex) {
System.err.println("File: " + ex);
}
}
}
 
Riaz Mohamed
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
have u mapped u'r servlet in web.xml
 
Erick Martin
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic