Wednesday, 19 February 2014

what is struts configuration file(struts.xml) ?

Struts Configuration Files

A Struts application uses a number of configuration files but the primary two are :-
1.struts.xml 
2.struts.properties.

In struts.xml you define all aspects of your application
  • Actions
  • Interceptors for each action.
  • Possible results for each action.
Interceptors and result types used in an action must be registered before they can be used.

Struts configuration files support inheritance and default configuration files are included in the struts2-core- VERSION.jar file.

struts-default.xml
                              It is default configuration file,which registers some default interceptors and result types, So you dont need to register them again and again for each action in your struts.xml file which makes it clean and short.

default.properties
                               The default.properties file, packaged in the same JAR, contains settings that apply to all Struts applications. As a result, unless you need to override the default values, you don't need to have a struts.properties file. Let's now look at struts.xml and struts.properties in more detail.

The struts.xml File

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
 ... 
</struts>

here <struts> is root element, there are many other element which comes between <struts> and </struts>

No comments:

Post a Comment