jsp登录系统 添加用户
添加方法
package com.gm.servlet;
import com.gm.service.IUserService;
import com.gm.service.impl.UserService;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
public class AddServlet extends HttpServlet {
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String username = request.getParameter("username");
String password = request.getParameter("password");
IUserService userService = new UserService();
userService.insert(username,password);
request.getRequestDispatcher("/find").forward(request,response);
}
}
查找方法
package com.gm.servlet;
import com.gm.Model.User;
import com.gm.service.IUserService;
import com.gm.service.impl.UserService;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;
public class FIndServlet extends HttpServlet {
IUserService userService = new UserService();
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
List<User> users = userService.finAll();
HttpSession session =request.getSession();
session.setAttribute("user1",users);
request.getRequestDispatcher("allUser.jsp").forward(request, response);
}
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
List<User> users = userService.finAll();
HttpSession session =request.getSession();
session.setAttribute("user1",users);
request.getRequestDispatcher("allUser.jsp").forward(request, response);
}
}
删除方法
public class DeleteServlet extends HttpServlet {
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String id1 = request.getParameter("id");
int id2 = Integer.parseInt(id1);
IUserService userService = new UserService();
userService.delete(id2);
request.getRequestDispatcher("/find").forward(request,response);
}
}
<a href="/delete?id=${user.id}">删除</a>|
129

被折叠的 条评论
为什么被折叠?



