Home Struts Struts Struts2.2.1 Databaseapps Configuring in struts.xml file 

Ask Questions?

View Latest Questions


 
 

Configuring in struts.xml file 
Posted on: February 5, 2011 at 12:00 AM
Advertisement
In this section, you will see how to configure an application in struts.

Configuring in struts.xml file

Configuration file--

It is a XML file that is holds all the configuration related information of a web application.
It initialize resources such as interceptors, constant,  actions and resources. It divide 
action in modular format. 

For a web application, we also require a filter mapping. So we needs one more XML
file name web.xml. It holds a filter.

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_9" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

<display-name>Struts HttpHeader Result Example</display-name>

<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>index.html</welcome-file>
</welcome-file-list>
</web-app>

struts.xml

<?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" />

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

<action name="loginPage">
<result>/resources/index.jsp</result>
</action>
<action name="addmission" method="display" class="net.roseindia.model.StudentAdmissionModel">
<result name="input">/resources/AdmissionForm.jsp</result>
</action>

<action name="AdmissionAction" class="net.roseindia.action.AdmissionAction">
<result name="success">/resources/AdmissionSuccess.jsp</result>
<result name="input">/resources/AdmissionForm.jsp</result>
</action>

<action name="searchForm" method="display" class="net.roseindia.model.SearchModel">
<result name="input">/resources/SearchStudentRecord.jsp</result> 
</action>

<action name="searchAction" class="net.roseindia.action.SearchAction">
<result name="input">/resources/SearchStudentRecord.jsp</result>
<result name="success">/resources/displayResult.jsp</result>
</action>

<action name="deleteForm">
<result>/resources/SearchForDelete.jsp</result> 
</action>

<action name="delete" class="net.roseindia.action.SearchForDelete">
<result name="success">/resources/SearchStudentRecord.jsp</result> 
</action>

<action name="updateForm" method="display" class="net.roseindia.model.UpdateModel">
<result name="input">/resources/updateForm.jsp</result> 
</action>

<action name="updateAction" class="net.roseindia.action.UpdateAction">
<result name="input">/resources/updateForm.jsp</result>
<result name="success">/resources/UdateSuccess.jsp</result>
</action>


</package>

</struts>


Related Tags for Configuring in struts.xml file :


DMCA.com