my dog learned polymorphism*
The moose likes Servlets and the fly likes sevlet error : Error allocating a servlet instance Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Servlets
Bookmark "sevlet error : Error allocating a servlet instance" Watch "sevlet error : Error allocating a servlet instance" New topic
Author

sevlet error : Error allocating a servlet instance

Ashwin Sharma
Greenhorn

Joined: Nov 03, 2006
Posts: 28
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

Joined: Apr 14, 2004
Posts: 10336

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?


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
shankar reddy
Ranch Hand

Joined: Jun 04, 2007
Posts: 71
I hope it will work , If you amend Logger without Final , Now check it once. Let me know the status.


Java Lover<br /> <br />Shankar Reddy <br />SCJP1.4 (88%)
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

When I create loggers I pass the name of the class to the constructor, not the class.

Logger.getLogger(HelloWorld.class.getName());


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
shankar reddy
Ranch Hand

Joined: Jun 04, 2007
Posts: 71
Yes Ben Souther ,That is correct . Ashwin , Now you can replace with , I am sure it will work.
Ashwin Sharma
Greenhorn

Joined: Nov 03, 2006
Posts: 28
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

Joined: Jun 04, 2007
Posts: 71
Could you post the code.
 
GeeCON Prague 2014
 
subject: sevlet error : Error allocating a servlet instance