📄 userinfoaction.java
字号:
package com.action;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionForm;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForward;
import com.domain.UserInfoForm;
import org.apache.struts.actions.LookupDispatchAction;
import java.util.Map;
import java.util.HashMap;
import java.io.UnsupportedEncodingException;
import com.dao.Chinese;
import com.dao.UserInfoDao;
public class UserInfoAction extends LookupDispatchAction {
private UserInfoDao dao = null;
public UserInfoAction() {
dao = new UserInfoDao();
}
protected Map getKeyMethodMap() {
Map map = new HashMap();
map.put("selectone","selectOneUserInfo");
map.put("update","updateUserInfo");
map.put("delete","deleteUserInfo");
return map;
}
//修改用户操作
public ActionForward updateUserInfo(ActionMapping mapping, ActionForm form,
HttpServletRequest request,
HttpServletResponse response) throws
UnsupportedEncodingException {
request.setCharacterEncoding("gb2312");
UserInfoForm userInfoForm = (UserInfoForm) form;
userInfoForm.setName(Chinese.chinese(request.getParameter("name")));
userInfoForm.setAge(userInfoForm.getAge());
userInfoForm.setProfession(Chinese.chinese(userInfoForm.getProfession()));
dao.updateUserInfo(userInfoForm);
request.setAttribute("success", "修改用户信息成功!!!");
return mapping.findForward("success");
}
//条件查询操作
public ActionForward selectOneUserInfo(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) throws
UnsupportedEncodingException {
request.setCharacterEncoding("gb2312");
Integer id = Integer.valueOf(request.getParameter("id"));
request.setAttribute("form", dao.userList(id));
return mapping.findForward("selectOne");
}
//删除用户操作
public ActionForward deleteUserInfo(ActionMapping mapping, ActionForm form,
HttpServletRequest request,
HttpServletResponse response) throws
UnsupportedEncodingException {
request.setCharacterEncoding("gb2312");
Integer id = Integer.valueOf(request.getParameter("id"));
System.out.println("id="+id);
dao.deleteUserInfo(id);
request.setAttribute("success", "删除用户信息成功!!!");
return mapping.findForward("success");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -