UserManagementAction.java
public class UserManagementAction extends ActionSupport {
List<User> usersList=new ArrayList();
UserService us=new UserServiceImpl();
User user;
int userId=0;
int userIds[];
public int getUserId() {
return userId;
}
public void setUserId(int userId) {
this.userId = userId;
}
public int[] getUserIds() {
return userIds;
}
public void setUserIds(int[] userIds) {
this.userIds = userIds;
}
public List<User> getUsersList() {
return usersList;
}
public void setUsersList(List<User> usersList) {
this.usersList = usersList;
}
public String getUserList() {
String str="userListsucc";
usersList=us.getUserList();
return str;
}
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
/*删除一条用户记录*/
public String delete() {
String str="deleteUserFail";
if(us.deleteUser(userId)!=0){
str="deleteUserSucc";
}
return str;
}
/*删除多条用户记录*/
public String userDeletes(){
String str="userDeletesFail";
for(int userId:userIds){
if(us.deleteUser(userId)!=0){
str="userDeletesSucc";
}
}
return str;
}
}
删除链接:
<a href='<s:url action="userDelete"><s:param name="userId" value="userId"/></s:url>'>Delete</a>
UserService.java添加:
public interface UserService {
public List<User> getUserList();
public int deleteUser(int bookId);
}
UserServiceImpl.java添加:
public int deleteUser(int userId) {
// TODO Auto-generated method stub
int bl=0;
String sql="delete from user_table"
+ " where userId="+userId;
bl=ub.executeUpdate(sql);
return bl;
}
struts.xml添加:
<action name="userDelete" class="jxnu.edu.cn.x3321.action.UserManagementAction"
method="delete">
<result name="deleteUserSucc" type="chain">userList</result>
<result name="deleteUserFail">/curp/error.jsp</result>
</action>
<action name="userDeletes" class="jxnu.edu.cn.x3321.action.UserManagementAction"
method="userDeletes">
<result name="userDeletesSucc" type="chain">userList</result>
<result name="userDeletesFail">/curp/error.jsp</result>
</action>
点击delete后