• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

java.lang.IllegalAccessException

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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");
}
 
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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");
}


}
}
 
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
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:
 
If you like strawberry rhubarb pie, try blueberry rhubarb (bluebarb) pie. And try this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic