I am half way through my struts eploration, suddenly i am bewildered by this question,
"why struts,and not an ordinary servlet?" "what paved way for their evolution?"
from the knowledge i got from various sources, struts uses more declarative traversing than ordinary servlets, am i right?. Are view and controller loosely coupled than ever before? The code quality of servlet increased?
what role does a controller play in struts framework? when and who call the controller? and how? in case of ordinary MVC, container calls the servlet using web.xml. Who read the struts-config.xml?i suppose it's the controller. Who call other action classes that does the actual work? again it's the controller, right?. what is the class name of the controller in struts?
if possible could you please reply with a complete life cycle of request-response cycle that uses struts framework. please use the actual class name, don't use generic names, like controller. please.
why not struts... it's a way to get people to use a MVC model instead of writing unorganized code that just looks bananas. Struts is a servlet that dispatches to different classes, just like spring mvc, they are defined in a configuration file instead of if checks in your servlet. Take a look at a sample application, from your questions it sounds like you don't have a good grasp of how to use struts or why. Have you tried reading the documentation on their website. I'm not familiar with Struts 2 (yet - soon will be), but I have used struts 1.x and Spring MVC and I like both of them.
Example I have a login jsp.
My login action will be my controller, get data from the jsp page (probably using a form submission), validate (using struts validation), then hand the data to a deeper layer to perform any business logic, ect. After it does that based on the service's response send it either back to the login page displaying the errors or a new page logged in.
krishna prasad gunasekaran
Joined: Jul 25, 2006
thank you, "Designing enterprise application with j2ee paltform", a pdf available in java.sun.com implies that Action classes are specially designed to minimize the code complexity of controller. it is the controller that calls the action classes. so is action the real controller or the controller(class name, please)is working behind the screen.
Joined: Jan 06, 2007
yes in my example I would have a class called LoginAction that extends struts Action. My struts config would configure the url /login.do to that action so when I submit my form to login.do it would execute the code in the class called LoginAction.
Struts is just a framework intended to provide a pattern to follow while giving you the ability to use a MVC approach. When I go back an look at my old code it is pretty much doing the same thing. Struts isn't the end all of MVC, it's just another way to get things done. If you go to Spring's website and read their documentation on MVC, I think that'll give you good idea of what spring mvc and struts and other MVC frameworks are trying to provide for developers:
sorry to answer your question, the servlet you map in your web.xml when using struts is your controller or dispatcher, it looks up info in the struts-config.xml according to the url. so when a request is made struts action looks to see if it should hand it off to one of your action classes (i.e. LoginAction).