This week's book giveaway is in the General Computing forum.
We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line!
See this thread for details.
The moose likes Servlets and the fly likes MVC without use of Struts Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Servlets
Reply Bookmark "MVC without use of Struts" Watch "MVC without use of Struts" New topic
Author

MVC without use of Struts

Vijay jai Singh
Greenhorn

Joined: Jan 07, 2009
Posts: 26
Hi all,

I am trying to develop a sample project which is based on MVC. I want to implement MVC without use of Struts.

Could you please help me regarding designing of application. I want to know how should i implement it

1) should i create a Controller Servlet and after submit on every jsp i should redirect to that Controller Servlet and based on request coming from JSP i should redirect to corresponding Servlet.

or 2) every servlet should work as controller and directly from JSP i should redirect to corresponding servlet.

or 3) any other approach i should follow.....

Thanks and regards
James Ward
Ranch Hand

Joined: Apr 27, 2003
Posts: 263
You can have One Servlet acting as Controller.
All your requests can point to this one servlet.
Based on something in the request, like a param value, url etc, you can invoke your business logic in a java class, and once done forward to a JSP page.

You can have a configuration file which stores information about what java class to invoke for a particular url/param-value, and which jsp to forward to. (which would be similar to struts-config file)
Nishan Patel
Ranch Hand

Joined: Sep 07, 2008
Posts: 676

James Ward wrote:You can have One Servlet acting as Controller.
All your requests can point to this one servlet.
Based on something in the request, like a param value, url etc, you can invoke your business logic in a java class, and once done forward to a JSP page.

You can have a configuration file which stores information about what java class to invoke for a particular url/param-value, and which jsp to forward to. (which would be similar to struts-config file)


Yes, James told you make one servlet which is work as Controller. Or you can divide your Servlet controller according to your module wise. Make different servlet according to application module.


Thanks, Nishan Patel
SCJP 1.5, SCWCD 1.5, OCPJWSD Java Developer,My Blog
Vijay jai Singh
Greenhorn

Joined: Jan 07, 2009
Posts: 26
Nishan Patel wrote:

Yes, James told you make one servlet which is work as Controller. Or you can divide your Servlet controller according to your module wise. Make different servlet according to application module.


Nishan as you are saying i can divide Servlet controller according to module wise. But generally it is preferred to have one controller in application. Correct me if i am wrong.

Thanks
Nishan Patel
Ranch Hand

Joined: Sep 07, 2008
Posts: 676

Yes, you are right, but what if your application is big and contains many module then it is hard to handle complexity with module. your module conflict with same controller servlet.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 56554
    
  14

Perhaps this article which outlines the various patterns involved, will be helpful.


[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: MVC without use of Struts
 
Similar Threads
Can JSF do this for me ?
STRUTS: WHY???
Accessing a variable from both EL and JSP Expression?
Struts Usage
about struts