aspose file tools*
The moose likes Struts and the fly likes STRUTS 2 : How to explicitly specify struts.xml in web.xml ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "STRUTS 2 : How to explicitly specify struts.xml in web.xml ?" Watch "STRUTS 2 : How to explicitly specify struts.xml in web.xml ?" New topic
Author

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

Manish Kumar Jain
Greenhorn

Joined: Feb 16, 2011
Posts: 6

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

Joined: Oct 29, 2001
Posts: 8997
    
    9

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

[How To Ask Questions On JavaRanch]
Manish Kumar Jain
Greenhorn

Joined: Feb 16, 2011
Posts: 6

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

Joined: Aug 29, 2008
Posts: 349
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

Joined: Feb 16, 2011
Posts: 6

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

Joined: Aug 29, 2008
Posts: 349
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

Joined: Oct 29, 2001
Posts: 8997
    
    9

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

Joined: Aug 29, 2008
Posts: 349
Oops, should have read more closely, sorry for the duplicate reply.
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8997
    
    9

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: STRUTS 2 : How to explicitly specify struts.xml in web.xml ?