• 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:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

IllegalAccessException in Tomcat

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have an XML file and i am using the SAX implementation of the xerces parser to parse the file. I have successfully created the custom object model of the xml file.
i have then created a servlet the code of which is given below. i am calling this servlet thru an html form. However, it gives an IllegalAccessException.
Pl let me know what could be the reason.
<thecode>
/*
* Author: Jayashree
* Created: 10/01/2001 12:51:33
* Modified: 10/01/2001 12:51:33
*/
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import org.xml.sax.*;
import org.xml.sax.helpers.*;
import org.apache.xerces.parsers.SAXParser;

class DocumentSAXParser extends HttpServlet
{
PrintWriter out = null;
public void init(ServletConfig cfg) throws ServletException
{
super.init(cfg);
}
public void doPost(HttpServletRequest req,HttpServletResponse res) throws IOException,ServletException
{
out = res.getWriter();
try
{
//InputStreamReader isr = new InputStreamReader(new URL("http://microcell:8080/jayashree/servlets/greeting1.xml")).openStream();
//InputSource is = new InputSource( isr );
//File filename = new File(req.getParameter("text"));
DocSAXHandler handler = new DocSAXHandler();
//DefaultHandler handler = new DefaultHandler();
//SAXParser parser = new SAXParser();
//String parserClassName = "com.sun.xml.parser.Parser";
org.xml.sax.XMLReader parser = new org.apache.xerces.parsers.SAXParser();
org.xml.sax.InputSource input = new InputSource(new FileReader("text1"));
// Full location of the file required
parser.setContentHandler( handler );
parser.parse(input);
//parser.setContentHandler(handler);
//parser.setErrorHandler(handler);
//parser.parse(filename);
}
catch(Exception e)
{
out.println(e.getMessage());
}
}
}
class DocSAXHandler extends DefaultHandler
{
private Document doc = new Document();
private Greeting g = null;
private Message m = null;
private String currentElement = null;
public Document getDocument()
{
return(doc);
}
public void startElement (String name, AttributeList atts)
{
String sname = name;
if(sname.equals("greeting"))
{
currentElement = "greeting";
}
else if(sname.equals("message"))
{
currentElement = "message";
}
else if(sname.equals("msgg"))
{
currentElement = "msgg";
}
else if(sname.equals("sendername"))
{
currentElement = "sendername";
}
else if(sname.equals("text"))
{
currentElement = "text";
}
for (int i = 0; i < atts.getLength(); i++)
{
String aname = atts.getName(i);
String type = atts.getType(i);
String value = atts.getValue(i);
}
}
public void endElement(String name)
{
if(name.equals("greeting"))
{
doc.addGreeting(g);
}
else if(name.equals("message"))
{
doc.addMessage(m);
}
}
public void characters( char ch[], int start, int length )
{
String value = new String( ch,start,length);
if(!value.trim().equals(""))
{
if( currentElement.equals("msgg") )
{
m.setMsgg( value );
}
else if( currentElement.equals("sendername") )
{
m.setSenderName( value );
}
else if( currentElement.equals("txt") )
{
m.setText( value );
}
}
}
}
</endof code>
Thanks!!!
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Without the full text of the exception, the code does not do much good. Print the stack trace in addition to the message!
Bill
 
jaya-shree
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This was the error i got on running the servlet
Error: 500
Location: /jayashree/servlet/DocumentSAXParser
Internal Servlet Error:
java.lang.IllegalAccessException: DocumentSAXParser
at java.lang.Class.newInstance0(Native Method)
at java.lang.Class.newInstance(Class.java:237)
at org.apache.tomcat.core.ServletWrapper.loadServlet(ServletWrapper.java:268)
at org.apache.tomcat.core.ServletWrapper.init(ServletWrapper.java:289)
at org.apache.tomcat.core.Handler.service(Handler.java:254)
at org.apache.tomcat.core.ServletWrapper.service(ServletWrapper.java:372)
at org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:797)
at org.apache.tomcat.core.ContextManager.service(ContextManager.java:743)
at org.apache.tomcat.service.http.HttpConnectionHandler.processConnection(HttpConnectionHandler.java:210)
at org.apache.tomcat.service.TcpWorkerThread.runIt(PoolTcpEndpoint.java:416)
at org.apache.tomcat.util.ThreadPool$ControlRunnable.run(ThreadPool.java:498)
at java.lang.Thread.run(Thread.java:484)
 
Sheriff
Posts: 5782
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your name jaya-shree does not comply with the JavaRanch naming policy. We require names to have at least two words, separated by a space, and strongly recommend that you use your full real name. Please spare a moment and re-register with a name that meets the requirements.
Thanks!
 
He got surgery to replace his foot with a pig. He said it was because of this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic