Ask Questions?

View Latest Questions


 
 

Mapping Application
Posted on: March 3, 2011 at 12:00 AM
Advertisement
Mapping Application

Mapping Application

The mapping is done within an action file called struts.xml. In the xml file you need to write the name of the action, their corresponding action class and results returned from the Action class. Before mapping in struts.xml you first need to map the struts filter in web.xml file as 

<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>

Then after map the action class and views in struts.xml file as
<action name="adminloginprocess" class="net.roseindiaAdmin.Action.AdminLoginAction">
	<result name="input">/AdminModule/adminlogin.jsp</result>
	<result name="error">/AdminModule/adminlogin.jsp</result>
	<result name="success">/AdminModule/adminloginsuccess.jsp</result>
</action>

Here input, error and success are string return by the method of action class. You can also specify the name of the method of an action class in mapping as
<action name="adminloginprocess" method="login" class="net.roseindiaAdmin.Action.AdminLoginAction">
	<result name="input">/AdminModule/adminlogin.jsp</result>
	<result name="error">/AdminModule/adminlogin.jsp</result>
	<result name="success">/AdminModule/adminloginsuccess.jsp</result>
</action>

remember the result name should be the same as the string returns from the method in the action class.
A simple struts.xml file is given below
<?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">
<action name="index">
	<result type="redirectAction">
		<param name="actionName">HelloWorld</param>
		<param name="namespace">/example</param>	
	</result>
</action>
</package>
</struts>


Related Tags for Mapping Application:


DMCA.com