📄 deleteuseraction.java
字号:
package org.ithinking.strutsExample.Action;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.ithinking.strutsExample.entity.Userinfo;
import org.ithinking.strutsExample.service.ServiceFactory;
import org.ithinking.strutsExample.service.UserInfoService;
import org.ithinking.utils.IntegerUtil;
public class DeleteUserAction extends Action {
// 删除用户的操作
public ActionForward execute(ActionMapping actionMapping,
ActionForm actionForm, HttpServletRequest httpServletRequest,
HttpServletResponse httpServletResponse) {
if (httpServletRequest.getParameter("id") == null
|| (!IntegerUtil.isInteger((String) httpServletRequest
.getParameter("id")))) {
ActionErrors errors = new ActionErrors();
errors.add(ActionErrors.GLOBAL_ERROR, new ActionError(
"global.findusererror"));
saveErrors(httpServletRequest, errors);
return actionMapping.findForward("deleteuser");
}
UserInfoService userInfoservice = ServiceFactory.getUserinfService();
Userinfo userInfo = userInfoservice.getUserInfoById(Integer
.valueOf((String) httpServletRequest.getParameter("id")));
if(userInfo==null)
{
ActionErrors errors = new ActionErrors();
errors.add(ActionErrors.GLOBAL_ERROR, new ActionError(
"global.errors.usernotexit"));
saveErrors(httpServletRequest, errors);
return actionMapping.findForward("deleteuser");
}
try {
if (userInfoservice.deleteUser(userInfo)) {
ActionErrors errors = new ActionErrors();
errors.add(ActionErrors.GLOBAL_ERROR, new ActionError(
"global.deletesuccess"));
saveErrors(httpServletRequest, errors);
return actionMapping.findForward("deleteuser");
} else {
ActionErrors errors = new ActionErrors();
errors.add(ActionErrors.GLOBAL_ERROR, new ActionError(
"global.deletefail"));
saveErrors(httpServletRequest, errors);
return actionMapping.findForward("deleteuser");
}
} catch (Exception ex) {
ex.printStackTrace();
ActionErrors errors = new ActionErrors();
errors.add(ActionErrors.GLOBAL_ERROR, new ActionError(
"global.errors.general"));
saveErrors(httpServletRequest, errors);
return actionMapping.findForward("error");
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -