1. For example:
When adding a department, click Save to go to the department list.
ADD teamAction: Adddepartmentaction
Show DepartmentAction: Listdepartmentaction
The Struts. xml configuration is as follows:
<Action name = "adddepartmentaction" class = "com. XK. Department. adddepartmentaction">
<Result name = "success" type = "Redirect"> listdepartmentaction. Action <result>
</Action>
<Action name = "listdepartmentaction" class = "com. XK. Department. listdepartmentaction">
<Result name = "success">/list. jsp </result>
</Action>
If you have other requirements, for example, after you click Save, you need to pass the ID (parentid) of the upper-level department to listdepartmentaction.
Modify the Struts. xml configuration:
<Action name = "adddepartmentaction" class = "adddepartmentaction">
<Result name = "success" type = "Redirect"> listdepartmentaction. Action? Parentid =$ {parentid} </result>
</Action>
<Action name = "listdepartmentaction" class = "listdepartmentaction">
<Result name = "success">/list. jsp </result>
</Action>
So how to obtain parentid =$ {parentid?
You need to configure a parentid attribute in adddepartmentaction, And the get () and set () methods must be available.
Package com. XK. Department;
Import javax. servlet. http. httpservletrequest;
Import org. Apache. struts2.servletactioncontext;
Import com. opensymphony. xwork2.actionsupport;
Import com. XK. OA. domain. Department;
Import com. XK. OA. Service. departmentservice;
Import com. XK. OA. util. requestutils;
@ Suppresswarnings ("serial ")
Public class adddepartmentaction extends actionsupport {
Private Department;
Private departmentservice;
Private long parentid;
Public long getparentid (){
Return parentid;
}
Public void setparentid (long parentid ){
This. parentid = parentid;
}
Public Department getdepartment (){
Return department;
}
Public void setdepartment (Department ){
This. Department = Department;
}
Public departmentservice getdepartmentservice (){
Return departmentservice;
}
Public void setdepartmentservice (departmentservice ){
This. departmentservice = departmentservice;
}
Public String execute () throws exception {
Httpservletrequest request = servletactioncontext. getrequest ();
This. parentid = long. parselong (request. getparameter ("parentid "));
Return success;
}
}