• Post Reply Bookmark Topic Watch Topic
  • New Topic

java.lang.IllegalAccessException

 
padraig cooney
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I get this error when I run my servlet:
java.lang.IllegalAccessException: tryTransform
I thought that it would be solved by making classes public, but to no avail.
In the system exception, there is this bit:
Exception in init tryTransform - java.lang.IllegalAccessException: tryTransform
I started my class like this:
public class tryTransform
Init is simply this:
public void init(ServletConfig config)
{
System.out.print("got here2");
}
 
Cynthia Yao
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what is your code in the servlet. Does this tryTransform is a bean class, and get called in a servlet? If you treat tryTransform as a servlet, then that is a problem. All servlet need to extends HttpServlet, and have init(), doGet(), and doPost().
 
padraig cooney
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's the code:
public class tryTransform extends HttpServlet{

public String HTML = new String();
public void init(ServletConfig config)
{
System.out.print("tryTransform servlet is initialised");
}

public void service(HttpServletRequest req,HttpServletResponse resp)
{
System.out.print("got here3");
try
{
resp.setContentType("text/html");
PrintWriter out = resp.getWriter();
resp.setStatus(HttpServletResponse.SC_OK);
TransformerFactory tfactory = TransformerFactory.newInstance();

// Create a transformer for the stylesheet.
Transformer transformer
= tfactory.newTransformer(new StreamSource("PNRetc.xsl"));

// Transform the source XML to System.out.

OutputStream outHTML = null;

transformer.transform( new StreamSource("presentResponseFF1.xml"),
new StreamResult(outHTML));

HTML = outHTML.toString();

out.print(HTML);

}
catch(Exception e)
{
System.out.println("Error occured");
}


}
}
 
padraig cooney
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's the code:
public class tryTransform extends HttpServlet{

public String HTML = new String();
public void init(ServletConfig config)
{
System.out.print("tryTransform servlet is initialised");
}

public void service(HttpServletRequest req,HttpServletResponse resp)
{
System.out.print("got here3");
try
{
resp.setContentType("text/html");
PrintWriter out = resp.getWriter();
resp.setStatus(HttpServletResponse.SC_OK);
TransformerFactory tfactory = TransformerFactory.newInstance();

// Create a transformer for the stylesheet.
Transformer transformer
= tfactory.newTransformer(new StreamSource("PNRetc.xsl"));

// Transform the source XML to System.out.

OutputStream outHTML = null;

transformer.transform( new StreamSource("presentResponseFF1.xml"),
new StreamResult(outHTML));

HTML = outHTML.toString();

out.print(HTML);

}
catch(Exception e)
{
System.out.println("Error occured");
}


}
}
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, for one thing, if you use this form of init:
public void init(ServletConfig config)
{
super.init( config ) ; // MUST HAVE THIS!!!
System.out.print("got here2");
}
Also - every time I see this I cringe:
catch(Exception e)
{
System.out.println("Error occured");
}
You are throwing away valuable information! At least do this:
catch(Exception e){ e.printStackTrace( System.err );
}
Bill

------------------
author of:
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!