Configure SwitchAction into struts-config.xml

Configure SwitchAction into struts-config.xml

Previous Home Next

 

When We want to used switchAction in our application. First create mapping in a switchAction into your struts-config.xml file.

 You perforn following step :-

1.Mapping in a switchAction into your struts-config.xml file.
2. create a forward or link to the SwitchAction that passes the page parameter and the module prefix parameter.

Example :-

struts-config.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC 
"-//Apache Software Foundation//DTD Struts Configuration 1.3//EN" 
"http://struts.apache.org/dtds/struts-config_1_3.dtd">     
<struts-config>  
<form-beans > 
<form-bean name="switchForm" type="r4r.co.in.SwitchForm" />
</form-beans>
<global-exceptions />
<global-forwards />
<action-mappings> 
<action path="/switch" type="org.apache.struts.actions.SwitchAction"/>  
<action path="/exampleswitchaction" type="r4r.co.in.SwitchAction" 
name="switchForm" input="/switch.jsp" parameter="method">       
<forward name="sum" path="/switch.do? page=/add.do;prefix=/add" redirect="true"/>    
<forward name="delete" path="/delete.jsp" redirect="true"/> 
</action>
</action-mappings> 
<message-resources parameter="r4r.co.in.ApplicationResources" />
</struts-config>

We have two struts-config.xml file.So  entry both struts files into web.xml  file.

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.5" 
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee   
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<servlet>   
<servlet-name>action</servlet-name>  
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
<init-param>   
<param-name>config</param-name>  
<param-value>/WEB-INF/struts-config.xml</param-value>  
</init-param>   
<init-param> 
<param-name>config/switch</param-name>     
<param-value>/WEB-INF/switch-config.xml</param-value>  
</init-param>  
<init-param>   
<param-name>debug</param-name>     
<param-value>3</param-value>  
</init-param>    
<init-param>    
<param-name>detail</param-name>      
<param-value>3</param-value>   
</init-param>   
<load-on-startup>0</load-on-startup> 
</servlet> 
<servlet-mapping>
<servlet-name>action</servlet-name> 
<url-pattern>*.do</url-pattern>  
</servlet-mapping>  
<welcome-file-list> 
<welcome-file>switch.jsp</welcome-file> 
</welcome-file-list>
</web-app> 


Previous Home Next