• 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

Servlet not being called

 
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
Can someone pl tell me why this servlet is not being called?


"Hello world " Servlet
----------------------


Deployment Descriptor
---------------------

testservlet folder in webapps/

testservlet.class is in webapps/testservlet/WEB-INF/classes

index.html is in webapps/testservlet/ folder

The deployment descriptor web.xml is in folder webapps/testservlet/WEB-INF/

index.html
----------

Now when i click on the 'Execute ' link on this page
http://www.knobe.org:8080/testservlet/
i get the error

HTTP - 500
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.

exception

javax.servlet.ServletException: Class testservlet is not a Servlet
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
java.lang.Thread.run(Unknown Source)


root cause

java.lang.ClassCastException: testservlet
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
java.lang.Thread.run(Unknown Source)

Subsequent requests generates the error..

HTTP Status 404 - Servlet testservlet is not available

type Status report

message Servlet testservlet is not available

description The requested resource (Servlet testservlet is not available) is not available.



At the same time the servlets-examples are working fine..ie if i click on the 'Execute' link on this index page, the example works.

http://www.knobe.org:8080/servlets-examples/

rgds
ben

[ December 16, 2006: Message edited by: chelakkad ben ]
[BSouther: Added UBB Code Tags]
[ December 16, 2006: Message edited by: Ben Souther ]
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

javax.servlet.ServletException: Class testservlet is not a Servlet



Try re-compiling your class and try again.
Restart your container as well.
Maybe the class file got corrupted.
 
chelakkad ben
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Ben,

Deleted the old class file, recompiled and restarted Tomcat. But still the same error is displayed...

HTTP Status 500 -
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.

exception
javax.servlet.ServletException: Class testservlet is not a Servlet
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
java.lang.Thread.run(Unknown Source)


root cause

java.lang.ClassCastException: testservlet
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool

Is there any prob with the configuration, i wonder?
rgds
csb
 
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try with this.



And try with this URL

 
chelakkad ben
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Rahul,
Now what is 'myApp'?
you mean <a href="testservlet/testservlet">Execute</a> or what?
i dont get it. pl clarify.
rgds
 
Rahul Bhattacharjee
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I wanted you to use
<url-pattern>/myApp/testservlet</url-pattern>
in place of
<url-pattern>/servlet/testservlet</url-pattern>

and change the anchor tag also to request /myApp/testservlet URL
instead of /servlet/testservlet

What I guess is , there is something called invoker servler in tomcat which has a pattern similar to what you have used ?(/servler/fullclassname).

I am guessing that you are using tomcat and you have not enabled the invoker servlet in the web.xml file.
Well there should not be a problem , but still I think you should try this , may be this helps.
 
chelakkad ben
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Rahul,
I tried what you said. Changed to 'myApp' in web.xml and index.html.
but getting the same HTTP - 500 error
rgds
 
Ranch Hand
Posts: 502
jQuery Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

java.lang.ClassCastException: testservlet



It seems like, the class container took for servicing request is not a class which implements HttpServlet.

Try packing your class and change <servlet-class>.
 
chelakkad ben
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Prabhu,
No need. The servlets-examples is working perfectly! Its /servlet/.. there.
ie. http://www.knobe.org:8080/servlets-examples/servlet/HelloWorldExample
works fine.
rgds
 
chelakkad ben
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello
Any one got the solution?
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Any URL that starts with "/servlet/" uses the invoker servlet mechanism, which works, but should not be used for reasons explained in that FAQ page.

Go with Rahuls suggestion of using URLs that include the name of your web app instead (myApp in his example), and double-check the mapping in web.xml.
 
chelakkad ben
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Dittmer,

In that case why is www.knobe.org:8080/servlets-examples working?

My app name is testservlet. This folder is in webapps. So the mapping in web.xml should be...

<web-app>
<servlet>
<servlet-name>testservlet</servlet-name>
<servlet-class>testservlet</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>testservlet</servlet-name>
<url-pattern>/testservlet/testservlet</url-pattern>
</servlet-mapping>
</web-app>

Is that correct? The second 'testservlet' in the url-pattern being the class file. And the index.html in webapps/testservlet/ should have
<a href="testservlet/testservlet">Execute</a> . Right?

rgds
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by chelakkad ben:
Hello Dittmer,

In that case why is www.knobe.org:8080/servlets-examples working?

My app name is testservlet. This folder is in webapps. So the mapping in web.xml should be...

<web-app>
<servlet>
<servlet-name>testservlet</servlet-name>
<servlet-class>testservlet</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>testservlet</servlet-name>
<url-pattern>/testservlet/testservlet</url-pattern>
</servlet-mapping>
</web-app>

Is that correct? The second 'testservlet' in the url-pattern being the class file. And the index.html in webapps/testservlet/ should have
<a href="testservlet/testservlet">Execute</a> . Right?

rgds



At a glance that all looks right.
Is it still not working?
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

And the index.html in webapps/testservlet/ should have
<a href="testservlet/testservlet">Execute</a> . Right?



This looks wrong. If index.html is in webapps/testservlet, then a URL of "testservlet/testservlet" would access "testservlet/testservlet/testservlet". Try either href="testservlet" or href="/testservlet/testservlet".
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Ulf Dittmer:


This looks wrong. If index.html is in webapps/testservlet, then a URL of "testservlet/testservlet" would access "testservlet/testservlet/testservlet". Try either href="testservlet" or href="/testservlet/testservlet".



Look at the URL pattern:
<url-pattern>/testservlet/testservlet</url-pattern>

/testservlet/testservlet/testservlet is what is needed in this case.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Calls into question whether naming everything testservlet is a good idea or not, no?
 
chelakkad ben
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
Its all a bit confusing!! I have changed the class name to Hello. So will this do?

<web-app>
<servlet>
<servlet-name>Hello</servlet-name>
<servlet-class>Hello</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>Hello</servlet-name>
<url-pattern>/testservlet/Hello</url-pattern>
</servlet-mapping>
</web-app>

and the index.html in webapps/testservlet/ folder
<a href="/testservlet/Hello">Execute</a> ?

rgds
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why do you insist upon making it harder than it needs to be?

Just make it:

<url-pattern>/Hello</url-pattern>
 
chelakkad ben
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello

'Why do you insist upon making it harder than it needs to be?'

Sorry. Not intentionally. New to servlets.
Wont repeat,once i learn them.

Changed to what you said...
<web-app>
<servlet>
<servlet-name>Hello</servlet-name>
<servlet-class>Hello</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Hello</servlet-name>
<url-pattern>/Hello</url-pattern>
</servlet-mapping>
</web-app>
and the index.html with
<a href="/testservlet/Hello">Execute</a>

But still the error remains
HTTP Status 500
exception
javax.servlet.ServletException: Class Hello is not a Servlet
Any changes needed in conf/web.xml?
rgds
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try one of my examples.
SimpleServlet is a basic "Hello, World" program like the one you're trying to deploy.
http://simple.souther.us

Just download the war file and drop it into your webapps directory.
See if that one runs properly.
If it does, then you know your server is OK,
You can then compare your code with the code in the example to see what might be different.
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
java.lang.ClassCastException means that your class have some problem. The tomcat don't think it as a servlet. Maybe your class don't have the post method.
 
Rahul Bhattacharjee
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by yu wang:
java.lang.ClassCastException means that your class have some problem. The tomcat don't think it as a servlet. Maybe your class don't have the post method.



There is no method in servlet named post and if you are talking about doPost method , then ,it inherits the default version of doPost method from HTTPServlet class.
 
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try this out




[BSouther: Added UBB CODE tags]
[ December 20, 2006: Message edited by: Ben Souther ]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic