no. of Servlets

New to MVC.

When we have an MVC model there may be so many JSP pages in the application and number of Java classes to do the business logic and store data. The servlet act as the controller. In a practical scenario will there be only one servlet which act as the controller?.i.e. all the JSP pages calls this controller and it redirects based on the request. Or will there be more than controller servlet.?

Please clarify.

thx

[459 byte] By [ujastian] at [2007-9-30 12:28:17]
# 1

> In a practical scenario will there

> be only one servlet which act as the controller?.i.e.

> all the JSP pages calls this controller and it

> redirects based on the request.

Ideally yes. There will be one controller servlet with all jsps submitting to the controller. For processing of requests the controller may invoke some class(called handlers, one for related use cases).

jSweep at 2007-7-4 15:59:39 > top of Java-index,Other Topics,Patterns & OO Design...
# 2
Yup, like he said. You can try the Struts Framework. It's designed in a way so that one servlet takes care of the controller actions.
n3philim at 2007-7-4 15:59:39 > top of Java-index,Other Topics,Patterns & OO Design...
# 3
thanks for the reply.U said servlet controller calls handlers. Is this handlers(Java classes) act as a controller again?Is no. of handlers depends on no. of types of request?thx
ujastian at 2007-7-4 15:59:39 > top of Java-index,Other Topics,Patterns & OO Design...
# 4

>Is this

> handlers(Java classes) act as a controller again?>

No. But it does work with request and response objects. The servlet instantiates the appropriate handler and calls a handler method and passes the request and response objects. In the handler method you can take appropriate action for request processing and forwarding to the appropriate jsps. Implementation of how the servlet instantiates the right handler is left to you(reflection is one solution).

>Is

> no. of handlers depends on no. of types of request?

Yes. As I said before, keep one handler class for related use cases.

However, if you want a cleaner solution and have enough time , go for a framework

jSweep at 2007-7-4 15:59:39 > top of Java-index,Other Topics,Patterns & OO Design...
# 5
Thanks a lot
ujastian at 2007-7-4 15:59:39 > top of Java-index,Other Topics,Patterns & OO Design...
# 6

> >Is

> > no. of handlers depends on no. of types of request?

> Yes. As I said before, keep one handler class for

> related use cases.

>

> However, if you want a cleaner solution and have

> enough time , go for a framework

He has a framework, just not one of the big ones like Struts (which IMO is not a good choice for most people).

jwenting at 2007-7-4 15:59:39 > top of Java-index,Other Topics,Patterns & OO Design...