Get the tools you need to learn Java skills fast!
Video tutorials, eBooks, hands-on lab exercises, sample code.
Get started
The moose likes Servlets and the fly likes Why service method doesn't run? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Badass: Making Users Awesome this week in the Game Development forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Why service method doesn Watch "Why service method doesn New topic

Why service method doesn't run?

anarkali perera
Ranch Hand

Joined: Sep 10, 2009
Posts: 237

when i run this it gives


as result.Why service method doesn't run?
Paul Clapham

Joined: Oct 14, 2005
Posts: 19357

See my answer on your crosspost.
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 62269

I've copied Paul's answer below and removed the other post.
Paul Clapham wrote:Some other method named service() with different parameters will have run.

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Praneeth Thiruveedhula

Joined: Oct 20, 2009
Posts: 19
in your program that service method is just like normal method.that method does't contain any parameters and does't throws any exception. so that is just like normal method. bydefault that method won't executes,and you have to call explacitly.

if you wrote the service method as follows then it may executes bydefault.

public void service(ServletRequest request,ServletResponse response)throws ServletException

Ashwin Bangar

Joined: Jul 02, 2009
Posts: 10
the service method you have written is an ordinary method and wont be called by the servlet container.
it is as if you have given a return type to constructor and hoping it to execute when you follow an object creation process.

Now Moving for SCWCD and then for OCA & OCP
I agree. Here's the link:
subject: Why service method doesn't run?