1.web.xml
<web-app> <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> <dispatcher>FORWARD</dispatcher> <dispatcher>REQUEST</dispatcher> <url-pattern>/*</url-pattern> </filter-mapping> </web-app>
All access will be intercepted fliter filter, which struts into the workflow of them.
2.struts.xml
<action name="addProduct" class="com.how2java.action.ProductAction" method="add"> <result name="list" type="redirect">listProduct</result> </action>
Find action according to the corresponding url.
3.Action
public String add() { System.out.println(product.getName()); System.out.println(product.getCategory().getName()); pdao.add(product); return "list"; }
action execute and return a String string back struts.xml
4.struts.xml
Centralized find the corresponding results from the results, forward or jump to the corresponding page or Action
5. Response Results