aspose file tools*
The moose likes Struts and the fly likes struts as MVC Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "struts as MVC " Watch "struts as MVC " New topic
Author

struts as MVC

subodh gupta
Ranch Hand

Joined: Jul 23, 2007
Posts: 203
Hi ranchers,

I want your help in understanding very novice concept MVC in struts what i understand is DispatcherServlet is Front Controller, jsp is view, FormBean is model and Action servlet is part of Controller.

PLease suggest me if am wrong some where.


http://subodh-gupta.blogspot.com
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
You're basically on the right track. What you're calling the "DispatcherServlet" is probably referring to the Struts ActionServlet class, and yes it is the main front conroller, and the JSP is the view. However, I wouldn't consider the ActionForm part of the model so much as a kind of "view helper", since it's tied so closely to the JSP.

The thing that's important to undertsand about Struts is that the framework itself contains no model components at all! The assumption is that you will write your own model classes using POJOs, EJBs, Spring, Hibernate, etc. following whatever patterns you deem most appropriate. You then just instantiate these model classes and call their methods from your Action classes, which you correctly identify as part of the controller.


Merrill
Consultant, Sima Solutions
subodh gupta
Ranch Hand

Joined: Jul 23, 2007
Posts: 203
i actually thought form as a part of model because it is used render the response in the jsp which is the concept of model.

Rest all is clear thanks.
Brent Sterling
Ranch Hand

Joined: Feb 08, 2006
Posts: 948
First off..."Front Controller" is a different pattern and related but not part of MVC. It is a bit of a stretch to apply the original MVC pattern as it applied to GUI application to a web application, so you have to twist some of the definitions. The view that I have (and that seems to be the most widely accepted view) is:
- Model = Database and Business Layer
- View = ActionForms and JSPs
- Controller = Actions and struts-config.xml.

I also have to assume you are talking about Struts 1.x. Your ActionForms (FormBean) are very Struts specific and tied to your JSP. With Struts 2 it is easier to use your Model objects (DTOs or POJOs) directly, but I am not if that is a good idea (I have only played around some with WebWork/Struts 2).

- Brent
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
The main objection I have to treating an ActionForm as a model object is that each ActionForm must extend org.apache.struts.action.ActionForm. One of the main rules of developing a model is that it should be completely independent of which view or controller components will be used to manipulate it.

Once I have model objects extending Struts objects (which is primarly a view and controller framework) I've tied my model to Struts. That means that if later I decide to use a comletely different view for the same model such as Java Swing, for example, I now have unwanted dependencies in my model.

It's OK for an ActionForm to have references to model objects, but the ActionForm should not itself be treated as a model object.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: struts as MVC