• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Liutauras Vilda
Sheriffs:
  • Paul Clapham
  • Jeanne Boyarsky
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
Bartenders:
  • Jesse Duncan
  • Frits Walraven
  • Mikalai Zaikin

FileNotFoundException

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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);
}
}
}
 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
pie. tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic