Struts 2 framework Configuration

The Struts 2 framework Configuration

Ther are the folloeing important files that s need to be create for the proper configuration of strtus 2 application  and the  Important configuration files are as follows : web.xml, struts.xml, struts-config.xmland struts.properties.

The web.xml file:

The web.xml configuration file is a J2EE configuration file that determines how elements of the HTTP request are processed by the servlet container. It is not strictly a Struts2 configuration file, but it is a file that needs to be configured for Struts2 to work. 

xml version="1.0" encoding="UTF-8"?>

<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">

<display-name>r4rdisplay-name>

<welcome-file-list>

<welcome-file>index.jspwelcome-file>

welcome-file-list>

<filter>

<filter-name>struts2filter-name>

<filter-class>

org.apache.struts2.dispatcher.FilterDispatcher

filter-class>

filter>

<filter-mapping>

<filter-name>struts2filter-name>

<url-pattern>/*url-pattern>

filter-mapping>

<welcome-file-list>

<welcome-file>Login.jspwelcome-file>

welcome-file-list>

</web-app>

 The struts.xml file:

Here, we are going to learn all about struts.xml file. First of all let us see the simple example of struts.xml file. Let`s have a look on one simple struts.xml file we created.

The struts.xml file contains the configuration information that you will be modifying as actions are developed or according to the development needs. This file can be used to override default settings for an application, for example struts.devMode = false and other settings which are defined in property file. This file can be created under the folder WEB-INF/classes. 

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>

<constant name="struts.enable.DynamicMethodInvocation" value="false" />

<constant name="struts.devMode" value="false" />

<constant name="struts.custom.i18n.resources" value="myapp" />

<package name="default" extends="struts-default" namespace="/">

<action name="login" class="r4r.LoginAction">

<result name="success">Welcome.jspresult>

<result name="error">Login.jspresult>

</action>

</package>

</struts>