aspose file tools*
The moose likes Struts and the fly likes StrutsConfig.xml dilemma Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "StrutsConfig.xml dilemma" Watch "StrutsConfig.xml dilemma" New topic
Author

StrutsConfig.xml dilemma

Kaustubh G Sharma
Ranch Hand

Joined: May 13, 2010
Posts: 1277

I have been asked several time this question can we create more than one strutsconfig.xml file or can we have more than one action servlet in our struts application... What would be the appropriate answer for this question or what is the intention to ask this question please let me know... thanks



No Kaustubh No Fun, Know Kaustubh Know Fun..
Shailesh Narkhede
Ranch Hand

Joined: Jul 10, 2008
Posts: 368
Hi,

Yes, we can have multiple struts-configs in single struts application. we can declare that in web.xml.

Thanks,
Shailesh
Kaustubh G Sharma
Ranch Hand

Joined: May 13, 2010
Posts: 1277

What about the ambiguity? and is there any particular reason to ask this question?
Sunny Bhandari
Ranch Hand

Joined: Dec 06, 2010
Posts: 448

Kaustubh G Sharma wrote:What about the ambiguity? and is there any particular reason to ask this question?


Hi Kaustubh,

I have also been asked this question 5 out of 20 interviews i have faced.
I have asked this question in 2 of the 5 interviews that I have taken.

Probably as a developer we focus on single files and don't have much knowledge about this aspect and interviews are simply to ask those absurd questions which have very less meaning in terms of actual work....

The answer is yes there can be multiple config files with comma separated to the ActionServlet in web.xml. The advantage is that we can split one big config to multiple smaller manageable configs.

In case of ambiguity the later one will override the earlier mapping. Its like refreshing a value for a key in hashmap.....


Java Experience
Kaustubh G Sharma
Ranch Hand

Joined: May 13, 2010
Posts: 1277

hmmm Thanks Sunny
Kaustubh G Sharma
Ranch Hand

Joined: May 13, 2010
Posts: 1277

Sunny Bhandari wrote:
Kaustubh G Sharma wrote:What about the ambiguity? and is there any particular reason to ask this question?


In case of ambiguity the later one will override the earlier mapping. Its like refreshing a value for a key in hashmap.....


didn't get this bro
Shailesh Narkhede
Ranch Hand

Joined: Jul 10, 2008
Posts: 368
Hi,

which version of struts you are using?
Including struts 1.1 and onwards they are supporting modules in struts application. In Module based application we can have multiple struts-configs for each module. All module & struts-configs need to declare in web.xml
Kaustubh G Sharma
Ranch Hand

Joined: May 13, 2010
Posts: 1277

1.3 it is.. but actually we don't create separate struts config file per module ..
manish krishnan
Greenhorn

Joined: May 11, 2010
Posts: 26
i think this link will help you

http://www.roseindia.net/struts/struts2/struts-xml.shtml

Thanking You
Manish
Sunny Bhandari
Ranch Hand

Joined: Dec 06, 2010
Posts: 448

Hi Kaustubh,

I meant that in case <param-value> in web.xml is a.xml,b,xml and both a and b xmls have same mapping then the mapping from b.xml will be used because it is loaded after a.xml has loaded and will override any conflicting mappings.
Shailesh Narkhede
Ranch Hand

Joined: Jul 10, 2008
Posts: 368
@Manish

As Kaustubh is using struts 1.3, He requires help on that as I see link you given it explores struts 2.0

@Kaustubh

refer below link,

configuration

look in to section "5.3.1 Module Configuration Files"

HTH

Thanks,
Shailesh
Kaustubh G Sharma
Ranch Hand

Joined: May 13, 2010
Posts: 1277

Thanks Shailesh you info really help me out... But as that article says we can separates multiple strutsconfig file with ',' ... Then Every time when request come to web.xml file then how it figure out which struts config is going to call??
Sunny Bhandari
Ranch Hand

Joined: Dec 06, 2010
Posts: 448

Kaustubh G Sharma wrote:Thanks Shailesh you info really help me out... But as that article says we can separates multiple strutsconfig file with ',' ... Then Every time when request come to web.xml file then how it figure out which struts config is going to call??


You forgot to read my reply on that?

I meant that in case <param-value> in web.xml is a.xml,b,xml and both a and b xmls have same mapping then the mapping from b.xml will be used because it is loaded after a.xml has loaded and will override any conflicting mappings.
Shailesh Narkhede
Ranch Hand

Joined: Jul 10, 2008
Posts: 368
While parsing all struts config files on start up, struts framework will parse all contains in single configuration object, if two struts config will have same action mapping name then that will be overridden. same thing is Sunny is trying to tell.
Prasanna Kumaar
Ranch Hand

Joined: Feb 08, 2011
Posts: 30
A Web.xml can have one or more Struts-Config.xml associated with it
Kaustubh G Sharma
Ranch Hand

Joined: May 13, 2010
Posts: 1277

Shailesh Narkhede wrote:While parsing all struts config files on start up, struts framework will parse all contains in single configuration object, if two struts config will have same action mapping name then that will be overridden. same thing is Sunny is trying to tell.


you want to say if more than one strutsconfig when associated with same mapping then the last strutsconfig will run.. And what about this ActionServlet can we have more than one ActionServlet?
Shailesh Narkhede
Ranch Hand

Joined: Jul 10, 2008
Posts: 368
Never
Kaustubh G Sharma
Ranch Hand

Joined: May 13, 2010
Posts: 1277

Shailesh Narkhede wrote:Never

what is the reason?
Sunny Bhandari
Ranch Hand

Joined: Dec 06, 2010
Posts: 448

Read Front Controller design pattern
Kaustubh G Sharma
Ranch Hand

Joined: May 13, 2010
Posts: 1277

Sunny Bhandari wrote:Read Front Controller design pattern


What is this?
Joachim Rohde
Ranch Hand

Joined: Nov 27, 2006
Posts: 423

http://lmgtfy.com/?q=Front%20Controller%20design%20pattern
Kaustubh G Sharma
Ranch Hand

Joined: May 13, 2010
Posts: 1277

Joachim Rohde wrote:http://lmgtfy.com/?q=Front%20Controller%20design%20pattern



hahaha thanks I got the solution for my stupid question .. Good one jack
Kaustubh G Sharma
Ranch Hand

Joined: May 13, 2010
Posts: 1277

I got this in one post...


ActionServlet is like BackBone of our application, we have done all actions(request & response) by using only one instance, that is ActionServlet's Instance, that is the main reason to go for MVC architecture, no need to create more than one instance, thats why we use only one ActionServlet for whole project.

In Previous Structure, we should create new instance for each and every request, in MVC no need.

Note of it "we have only one Backbone in our BODY"
 
jQuery in Action, 2nd edition
 
subject: StrutsConfig.xml dilemma