This week's book giveaway is in the Agile and other Processes forum. We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line! See this thread for details.
Im new to Struts2.... I have some few doubts below...
a) In Struts2, how does it find struts.xml?? (we dnt define struts.xml in web.xml file unlike in Struts1 which we define struts-config.xml in web.xml file, so how its going to see that struts.xml file)
b) why dont we write "extends ActionSupport" for our "Action" class.. I have seeen many examples without extending with any other predefined Action class.. How does it find execute() method or populate() method in our Action class if we dnt extend any other predefined action class or implement Action interface methods ??
a) the default behavior is to look for struts.xml file at the root of the classes directory. Even I think in Struts 1, if you don't give any details in web.xml, it automatically looks for struts-config.xml. You can override this default behavior through the web.xml file.
b) Struts 2 can use POJOs as actions. So your action need not extend or implement any Struts class/interface. By default struts looks for a method named "execute" in your action class. You can however configure your action to execute any method when a request is received...
Ankit Garg wrote:a) the default behavior is to look for struts.xml file at the root of the classes directory. Even I think in Struts 1, if you don't give any details in web.xml, it automatically looks for struts-config.xml. You can override this default behavior through the web.xml file.
In Struts1, if we look at the code for ActionServlet, then you can see that by default the value for "config" = "/WEB-INF/struts-config.xml" , so thats the reason even if we dont specify the path for struts-config.xmlin web.xml, it takes that default value.. Assume if we change the name of struts xml file or if we change the path for it, then we MUST definitely has to specify that config value in web.xml, otherwise it cannot see...
But Im not understandng exactly in case of Struts2.. How does it find "struts.xml" file and how does it look for execute and populate methods automatically..
I will be very much appreciated if anyone would give an exact answer for my doubt... waiting for..
Harishwar Madhya wrote:How does it find "struts.xml" file
It tries loading it.
and how does it look for execute and populate methods automatically..
Reflection, if the class doesn't implement Action.
Harishwar Madhya
Greenhorn
Joined: Sep 01, 2010
Posts: 14
posted
0
Hey david, thanks for your reply... Whats the concept of Reflection?? Could you explain what it is?
you said "It tries loading it." ?? means?? There should be some way to know about struts.xml file for the application.. Any idea how does our application knows where does struts.xml placed ??
Assuming the developer hasn't explicitly defined a config file location, S2 will attempt to load struts.xml from the root of the classpath as a resource. I'm not sure what else I can tell you--a resource either exists at a given location, or it doesn't. If it's there, it'll get processed. If it's not, it won't.
Harishwar Madhya
Greenhorn
Joined: Sep 01, 2010
Posts: 14
posted
0
Yeah I agree that if our struts.xml file will be there inside /WEB-INF folder, then it automatically loads that file.. But my actual doubt is "How does it look that file"?? If anyone knows please kindly tell me.. :)