Wednesday, June 22, 2011

Error instantiating servlet 'action'.


Error instantiating servlet 'action'. Servlet class org.apache.struts.action.ActionServlet not found

The error might mislead you to think that it is not able to find struts.jar and you might start struggling on finding why it is not able to find struts.jar. If you have started looking on this path, then just wait.... Lets make sure that the reason is missing struts.jar or something else?

This happened with me while working on my project, during a new deployment, i started getting this exception and three people of my team including me spent around 8 hours without any output and without being able to figure out the root cause of the problem.

Then I searched on internet and found a solution, which I thought is not worth devoting time and trying it out. But actually i was wrong. i could have saved 4-5 hours if I would have tried that option when I first found it.

The approach to tackle such an error is

The error message might be misleading in some cases. Let us verify whether it is correct. Can you try removing all servlet-class and servlet-mapping in your web.xml ? Then add a jsp that has

<% Class.forName("org.apache.struts.action.ActionServlet"); %>
   Class "org.apache.struts.action.ActionServlet" is loaded. 

deploy your application and access the jsp. Please tell me what happens.

In many cases, it will fail with an error message in the application.log of the enclosing application that shows the root cause: another missing class that is needed in order to loade the servlet class. To remove the problem, include the missing classes into your web application classpath.

Note : If you find missing ActionServlet.class then rather than jumping to conclusion that struts.jar is missing, just think about this possible way to find out the solution

Source : http://forums.oracle.com/forums/thread.jspa?messageID=1352351

2 comments: