1.今天学习了
编写添加用户的 Servlet
-
package edu.swpu.web.servlet;
-
-
import edu.swpu.domain.User;
-
import edu.swpu.service.UserService;
-
import edu.swpu.service.impl.UserServiceImpl;
-
import org.apache.commons.beanutils.BeanUtils;
-
-
import javax.servlet.ServletException;
-
import javax.servlet.annotation.WebServlet;
-
import javax.servlet.http.HttpServlet;
-
import javax.servlet.http.HttpServletRequest;
-
import javax.servlet.http.HttpServletResponse;
-
import java.io.IOException;
-
import java.lang.reflect.InvocationTargetException;
-
import java.util.Map;
-
-
-
public class AddUserServlet extends HttpServlet {
-
-
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
-
//1.设置编码
-
request.setCharacterEncoding("utf-8");
-
//2.获取参数
-
Map<String, String[]> map = request.getParameterMap();
-
//3.封装对象
-
User user = new User();
-
try {
-
BeanUtils.populate(user,map);
-
} catch (IllegalAccessException e) {
-
e.printStackTrace();
-
} catch (InvocationTargetException e) {
-
e.printStackTrace();
-
}
-
//4.调用Service保存
-
UserService service = new UserServiceImpl();
-
service.addUser(user);
-
//5.跳转到userListService,因为没有共享数据,所以使用重定向
-
response.sendRedirect(request.getContextPath()+"/userListServlet");
-
-
}
-
-
-
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
-
super.doGet(request, response);
-
}
-
}
2.没有遇到问题
3.明天打算学习
修改用户信息列表 userlist.jsp