CodesJava

Easy learning with example program codes

Struts 2 Configuration Files


Struts.xml file:

The struts.xml is the core configuration file for struts framework. The struts.xml is used to initialize the resources like Interceptors, Action classes and Results.

Syntax:

<struts>
 
   <package name="packageName" extends="struts-default">
 
      <action name="actionName" class="actionClass" method="methodName">
            <result name="success">/HelloWorld.jsp</result>
      </action>
 
      //more actions.
 
   </package>
 
   //more packages.
 
</struts>

Commonly used attributes:

1. package attribute: It is used for modularization. You can divide configuration into multiple modules.

2. action attribute: It is a sub-attribute of the package attribute. It represents an action.

3. result attribute: It is a sub-attribute of the action attribute. It is used to control the flow after an action is executed.

web.xml:

The web.xml is known as deployment descriptor. It is used for providing entry point in any web application. In struts 2 we have to define FilterDispatcher class entry in web.xml.

web.xml file example:

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" 
	xmlns="http://java.sun.com/xml/ns/javaee" 
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
	xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
	http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
 
 
<filter>
 <filter-name>struts2</filter-name>
 <filter-class>
  org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
 </filter-class>
</filter>
 
<filter-mapping>
  <filter-name>struts2</filter-name>
  <url-pattern>/*</url-pattern>
</filter-mapping>
 
<welcome-file-list>
  <welcome-file>login.jsp</welcome-file>
</welcome-file-list>
 
</web-app>

 
Next Topic: Action in struts 2.
Previous Topic: Struts 2 Architecture.

Related Topics:

How to build java project using ant in eclipse?
JAXB marshalling – convert java object to xml example.
How to create pdf file in java using iText jar?
Generics class example.
OGNL in struts 2.
Hibernate One-to-One Mapping using xml.
Send inline image in email using JavaMail API.
Quartz 2 JobListener example.

 



Industrial Training

We offers Placement Oriented Training on Java, Spring, JSF, Hibernate, PHP, AngularJS, Angular 4, PLSQL, Oracle BI Publisher etc. We also provides Online training, please mail us at hr@codesjava.com.

Development

We also provides the Development services for Website Development , Java Development, PHP Development, Android App Development etc. You can contact us on hr@codesjava.com.

Copyright © 2019 CodesJava DMCA.com Protection Status SiteMap Reference: Java Wiki