?? userupdatedo.java
字號:
package com.lovo.servlet;
import java.io.IOException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.lovo.factory.BOFactory;
import com.lovo.po.LevelPO;
import com.lovo.po.UserPO;
import com.lovo.po.UserTypePO;
public class UserUpdateDO extends HttpServlet {
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
this.doPost(request, response);
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setCharacterEncoding("utf-8");
response.setContentType("text/html;charset=utf-8");
response.setCharacterEncoding("utf-8");
// 1.接收參數
RequestDispatcher rd = request.getRequestDispatcher("error.jsp");
String levelStr = request.getParameter("level");
String wealthStr = request.getParameter("wealth");
String email = request.getParameter("email");
String userTypeStr = request.getParameter("usertype");
String idStr = request.getParameter("id");
int id = 0;
int levelId = 0;
int userTypeId = 0;
int wealth = 0;
//2.校驗
if(idStr.matches("\\d+")) {
id = Integer.parseInt(idStr);
} else {
response.sendRedirect("../web/error.jsp?errorInfo=Data Error");
return;
}
if(levelStr.matches("\\d+")) {
levelId = Integer.parseInt(levelStr);
} else {
response.sendRedirect("../web/error.jsp?errorInfo=Data Error");
return;
}
if(userTypeStr.matches("\\d+")) {
userTypeId = Integer.parseInt(userTypeStr);
} else {
response.sendRedirect("../web/error.jsp?errorInfo=Data Error");
return;
}
if(wealthStr.matches("\\d+")) {
wealth = Integer.parseInt(wealthStr);
} else {
response.sendRedirect("../web/error.jsp?errorInfo=Data Error");
return;
}
//3.封裝
UserPO po = BOFactory.getUserBOInstance().queryById(id);
po.setEmail(email);
LevelPO level = new LevelPO();
level.setId(levelId);
UserTypePO userType = new UserTypePO();
userType.setId(userTypeId);
po.setUserType(userType);
po.setLevel(level);
po.setWealth(wealth);
boolean isUpdateSuc = BOFactory.getUserBOInstance().modifyInfo(po);
if(isUpdateSuc) {
response.sendRedirect("UserMagDO");
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -