• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

sevlet error : Error allocating a servlet instance

 
Ashwin Sharma
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi
I am using tomcat 6. My servlet hello world is working fine on it. But when i uses log4j api its not working and i get following error-
{ The server encountered an internal error () that prevented it from
fulfilling this request.
exception
javax.servlet.ServletException: Error allocating a servlet instance }
Again when i uncomment the logger statement, and restart the tomcat, still i get same error unless i restart my computer.
I have put log4j property file in web-inf/classes directory and my helloWorld example is -
{
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import org.apache.log4j.Logger;
public class HelloWorld extends HttpServlet
{
private static final Logger logger = Logger.getLogger(HelloWorld.class);

public void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOExc
{
logger.info(":::::::::::::::::::::::::::");
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<head><title>Hello World </title></head>");
out.println("<body>");
out.println("<h1>Hello World</h1>");
out.println("</body>");
}
}
}
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The stacktrace should tell you more than this. My guess is you really have something like a NoClassDefFound error or somehting like that. Can you post the full stacktrace?
 
shankar reddy
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I hope it will work , If you amend Logger without Final , Now check it once. Let me know the status.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When I create loggers I pass the name of the class to the constructor, not the class.

Logger.getLogger(HelloWorld.class.getName());
 
shankar reddy
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes Ben Souther ,That is correct . Ashwin , Now you can replace with , I am sure it will work.
 
Ashwin Sharma
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
below is stack trace -


May be some thing to do with tomcat internal logger(i assume there is some conflict while loading logger api for the first time), because now after i restarted the computer with the logger(log4j) code its working.
 
shankar reddy
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could you post the code.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic