1. Create a project first
2. Two jsps need to be created in this project
1) Write a sentence in the first JSP
<body>user ADD success!</body>
2) write a link in the second JSP
<body>action does not have to execute the Execute method <br/> can configure the action in the configuration file with method= To specify which method to execute or dynamically specify in the URL address (dynamic method call DMI) (recommended) <br/><a href= "<%=context%>/user/useradd" > Add Users </a> <BR/><a href= "<%=context%>/user/user!add" > Add user </a><br/> The former will generate too much action, so it is not recommended to use < /body>
3.java Backstage
public class Useraction extends Actionsupport {public String Add () {return SUCCESS;}
This function adds a user
4. Write in Struts.xml
<struts> <constant name= "Struts.devmode" value= "true"/> <package name= "user" extends= " Struts-default "namespace="/user "> <action name=" UserAdd "class=" Com.bjsxt.struts2.user.action.UserAction "method=" Add "> <result>/user_add_success.jsp</result > </action> <action name= "user" class= "com.bjsxt.struts2.user.action.UserAction" > <result>/user_add_success.jsp</result> </action> </package></struts>
For page jumps
5. Finally, please do not forget to write this sentence in Web. xml
<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>
Dynamic Method Invocation