Struts Tutorial - Code Examples
Struts Tutorial - Code Examples
Struts Tutorial - Code Examples
Struts Flow start with ActionServlet then call to process() method of RequestProcessor.
Any struts web application contain the ActionServlet configuration in web.xml file.
On load-on-startup the servlet container Instantiate the ActionServlet .
First Task by ActionServlet : The ActionServlet takes the Struts Config file name as an init-param.
At startup, in the init() method, the ActionServlet reads the Struts Config file and load into memory.
Second Task by ActionServlet : If the user types http://localhost:8080/app/submitForm.do in the
browser URL bar, the URL will be intercepted and processed by the ActionServlet since the URL has a
pattern *.do, with a suffix of "do". Because servlet-mapping is
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
Third Task by ActionServlet : Then ActionServlet delegates the request handling to another class
called RequestProcessor by invoking its process() method.
<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>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<action path="/submitForm"
type="com.techfaq.emp.EmpAction"
name="EmpForm"
scope="request"
validate="true"
input="EmpForm.jsp">
<forward name="success"
path="success.jsp"/>
<forward name="failure" path="failure.jsp" />
</action>