wood burning stoves 2.0*
The moose likes Servlets and the fly likes Servlet not being called Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Servlet not being called " Watch "Servlet not being called " New topic
Author

Servlet not being called

chelakkad ben
Ranch Hand

Joined: Feb 09, 2005
Posts: 62
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 ]
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

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.


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

Joined: Feb 09, 2005
Posts: 62
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
Rahul Bhattacharjee
Ranch Hand

Joined: Nov 29, 2005
Posts: 2308
Try with this.



And try with this URL



Rahul Bhattacharjee
LinkedIn - Blog
chelakkad ben
Ranch Hand

Joined: Feb 09, 2005
Posts: 62
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

Joined: Nov 29, 2005
Posts: 2308
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

Joined: Feb 09, 2005
Posts: 62
Rahul,
I tried what you said. Changed to 'myApp' in web.xml and index.html.
but getting the same HTTP - 500 error
rgds
Prabhu Venkatachalam
Ranch Hand

Joined: Nov 16, 2005
Posts: 502



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>.


Prabhu Venkatachalam<br />SCJP 1.4,SCWCD 1.4<br />prabhu.venkatachalam@gmail.com
chelakkad ben
Ranch Hand

Joined: Feb 09, 2005
Posts: 62
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

Joined: Feb 09, 2005
Posts: 62
Hello
Any one got the solution?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41599
    
  55
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.


Ping & DNS - my free Android networking tools app
chelakkad ben
Ranch Hand

Joined: Feb 09, 2005
Posts: 62
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

Joined: Dec 11, 2004
Posts: 13410

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
Marshal

Joined: Mar 22, 2005
Posts: 41599
    
  55
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

Joined: Dec 11, 2004
Posts: 13410

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.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61092
    
  66

Calls into question whether naming everything testservlet is a good idea or not, no?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
chelakkad ben
Ranch Hand

Joined: Feb 09, 2005
Posts: 62
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
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61092
    
  66

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

Joined: Feb 09, 2005
Posts: 62
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

Joined: Dec 11, 2004
Posts: 13410

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.
yu wang
Greenhorn

Joined: Dec 12, 2006
Posts: 4
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

Joined: Nov 29, 2005
Posts: 2308
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.
Shashi Kant
Ranch Hand

Joined: Aug 08, 2006
Posts: 117
Try this out




[BSouther: Added UBB CODE tags]
[ December 20, 2006: Message edited by: Ben Souther ]

If it's true that we are here to help others, then what exactly are the others here for?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Servlet not being called