Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

STRUTS 2 : How to explicitly specify struts.xml in web.xml ?

 
Manish Kumar Jain
Greenhorn
Posts: 6
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am new to Struts2.... I have a doubt....

a) In Struts2, how does it find struts.xml?? (we dont 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)

I want my struts.xml file to have a different name like learn-struts.xml, how should I explicitly specify in web.xml ? Can someone please let me know the XML configuration ?

I tried using the following but did not work:
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
<init-param>
<param-name>actionPackages</param-name>
<param-value>manning</param-value>
</init-param>
<init-param>
<param-name>config</param-name>
<param-value>learnstruts.xml</param-value>
</init-param>
</filter>

Waiting for quick reply...

Manish
 
Joe Ess
Bartender
Pie
Posts: 9265
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the JavaRanch.
You cannot change the name of struts.xml. You can, however, break up the Struts configuration among several configuration files which are named in strtus.xml.
Struts 2 FAQ: Configuration files
 
Manish Kumar Jain
Greenhorn
Posts: 6
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Joe,

Thanks for the quick response...

One last question.. is there a way I can put my struts.xml file in some other location and specify that path in the web.xml ?

If so, can you please let me know the XML configuration in Struts 2 ?


Regards,
Manish
 
Tom Rispoli
Ranch Hand
Posts: 349
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I believe that the struts.xml file needs to reside in the classpath. My client required that the struts.xml file not be stored under the application server's directories. To handle this, we specified the directory that they wanted to use as part of the class path in the application server's configuration for our server instance.
 
Manish Kumar Jain
Greenhorn
Posts: 6
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Tom,

Could you please let me know in which file did you specify this and can you please let me know the XML configuration ?

Manish
 
Tom Rispoli
Ranch Hand
Posts: 349
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thats going to be application server specific. In glassfish 2 you get to it in the command console through the configuration for your application server instance. JVM Settings -> Path Settings.
 
Joe Ess
Bartender
Pie
Posts: 9265
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tom Rispoli wrote:I believe that the struts.xml file needs to reside in the classpath.


That's what the FAQ I linked to says

As for how to set the server classpath, that depends on the server. This is a Bad Idea for two reasons (off the top of my head). First, deviating from the standard will confuse developers who later have to maintain the application. They expect struts.xml to be in WEB-INF/classes. Why make things difficult? Second, what happens when someone tries to deploy a second Struts application on the server?
 
Tom Rispoli
Ranch Hand
Posts: 349
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oops, should have read more closely, sorry for the duplicate reply.
 
Joe Ess
Bartender
Pie
Posts: 9265
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tom Rispoli wrote:Oops, should have read more closely, sorry for the duplicate reply.


My comment wasn't directed at you
Neither is my critique of changing the server classpath. That's what the client wants, that's what we do. Of course, we should also let them know the impact of such a choice.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic