IndexPage of Strut2application
IndexPage of Strut2application
3)struts2application/WEB-INF/lib -contains all struts2 jar files 4)struts2application/WEB-INF-contains the struts.xml file. 5)web.xml-Servlet configurations. Commonly required jar files ============================ 1)commons-logging-1.1.jar 2)freemaker-2.3.8.jar 3)ognl-2.6.11.jar 4)struts2-core-2.0.6.jar 5)xwork-2.0.1.jar Example Program =============== index.jsp This file has three inputs name,age,salary to get input from user. client.jsp This page displays the output when the user submitted the input. error.jsp This page is used displayed if user enters wrong information ClientAction.java Action class is used to process the data entered from index.jsp page and it returns an appropriate result code. web.xml DD of Web application struts.xml struts2 configuration file containing action mappings. mystyle.css style sheet used for decoration View
===== index.jsp error.jsp client.jsp Working Procedure of program ============================ 1)User enter the data in index.jsp page and it is submitted by submit Button. 2)The browser invokes the url of the form tag with its action attribute value 3)The jsp/servlet container receives request and looks for <filter-mapping> with the matching<url-pattern> in web.xml file. 4)The container finds the following entry, which tells the container to send the request to a servlet filter that is deployed with filter name-strut2. <filter-mapping> <filter-name>strut2</fiter-name> <url-pattern>/*</url-pattern> </filter-mapping> 5)The web container find the folowing filter entry with fiter name that points to FilterDispatcher which acts as a controller of our struts application <filter> <filter-name>struts2</filter-name> <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class> </filter> 6)After submitting the form, the value of action attribute of form <s:form action="ClientAction"> is matched with the action mapped in struts.xml file with name=ClientAction.The FilterDispatcher looks for an action mapping entry in the struts.xml file.It finds the following entry <action <result <result <result name="clientAction" class="com.kogent.action.ClientAction"> name="success">/client.jsp</result> name="error">/error.jsp</result> name="input">/error.jsp</result>
</action> 7)For using action mapping in struts.xml it creates an instane of ClientAction Action class, which is responsible for processing data sent from index.jsp and forwards the result to the specific view. Before the execute() method of clientAction class is executed,all input properti es of the Action class are populated with the input parameters having the same name. Eg: setName is used to set the name properties of Action class.
8)Inside the execute() method of ClientAction class returns success value then c lient page is displayed.