Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Servlet and SAX Error

 
dan jensen
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, I am trying to parse xml sent via HTTP within a servlet. I've created a class, Echo, which handles the parsing of the data. I call the Echo class from my servlet, providing it the xml data. I am getting the following error message when I compile:
cannot resolve symbol
symbol : constructor Echo ()
location: class Echo
DefaultHandler handler = new Echo();
Anyone have any idea how I can resolve this error?

Here is my code:
import java.io.*;
import java.util.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class GreetingServlet extends HttpServlet {
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException
{
String DATA = request.getParameter("DATA");
if(DATA != null){
Echo pXML = new Echo(DATA);
}
}
}
import java.io.*;
import org.xml.sax.*;
import org.xml.sax.helpers.DefaultHandler;
import javax.xml.parsers.SAXParserFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
public class Echo extends DefaultHandler
{
public Echo(String instring)
{
// Use an instance of ourselves as the SAX event handler
DefaultHandler handler = new Echo();
....
}
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13071
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Since you have specified a constructor that uses a String, the compiler won't automatically supply a no-args constructor as in your line.
DefaultHandler handler = new Echo();
But it seems to me you don't want to install another Echo - you want to use "this" Echo.
Bill
 
dan jensen
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you William. That was very helpful. I am fairly new to Java so excuse some of questions. I was able to compile it successfully.
Dan
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic