Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

tomcat returns strange error

 
Vas Miriyala
Ranch Hand
Posts: 114
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
here is the error i got when i try to run servlet

Here is my java code for Hello.java

here is web.xml

here is the information about java in my machine

please help me out ...I am struglling a lot
 
Anirvan Majumdar
Ranch Hand
Posts: 261
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you check and verify whether the servlet API JAR is available in your Tomcat installation. The JAR is typically named servlet-api.jar.
I recall a similar error - could not instantiate servlet class - which arose due to the absence of that JAR file. In a normal Tomcat installation this JAR is always included by default, but still you might want to check on that first.
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 11865
194
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The error is stating that you do not have the "public" modifier set on the class - did you try your class one time with default permissions? Have you redeployed since you set public access?

You might want to go to the version of the web application that Tomcat is actually running, and try decompiling the class to see what access Tomcat believes it has. E.g.:

Obviously change paths as needed according to your installation, and ServletTest to whatever you have named your web application.

You should hopefully see some output like this:

Copy and paste that output into this topic.

I suspect you will find that your output will look like this:

Notice the lack of a "public" in the line "class Hello extends javax.servlet.http.HttpServlet"?
 
Vas Miriyala
Ranch Hand
Posts: 114
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for your valuable suggestions ,the strange thing is that once again i have written simple servlet and deployed it in servlet container and working fine still i am not getting that whats went wrong in my earlier code looks same and onething i did is restarted the system,thats it
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 11865
194
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As I said - the error message states that you did not have your class defined as public previously. The code you posted shows that it is public, so at some point you may have changed the code without redeploying. Now that you have redeployed with a public class the problem has gone away.

You can prove this yourself by removing the public access modifier from your class on your working application, recompiling and redeploying - you should get the same error you were previously seeing.
 
Vas Miriyala
Ranch Hand
Posts: 114
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
well thanks a lot..tired..got the same error..great nice job thanks a lot
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic