基于javaweb+mysql的jsp+servlet家政服务系统(java+jsp+jquery+servlet+mysql)
这是一个基于JavaWeb技术栈的JSP和Servlet家政服务系统的简化版本。以下是系统的核心功能和部分代码示例:
// Servlet处理用户登录
@WebServlet("/login")
public class LoginServlet extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String username = request.getParameter("username");
String password = request.getParameter("password");
UserService userService = new UserServiceImpl();
User user = userService.login(username, password);
if (user != null) {
request.getSession().setAttribute("user", user);
response.sendRedirect("home.jsp");
} else {
response.sendRedirect("login.jsp");
}
}
}
// Servlet处理订单
@WebServlet("/order")
public class OrderServlet extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String serviceName = request.getParameter("serviceName");
String serviceDate = request.getParameter("serviceDate");
String serviceTime = request.getParameter("serviceTime");
String address = request.getParameter("address");
String userId = request.getParameter("userId");
OrderService orderService = new OrderServiceImpl();
boolean isSuccess = orderService.placeOrder(serviceName, serviceDate, serviceTime, address, userId);
if (isSuccess) {
response.sendRedirect("home.jsp");
} else {
response.sendRedirect("order.jsp");
}
}
}
// 服务类实现用户登录
public class UserServiceImpl implements UserService {
public User login(String username, String password) {
UserDao userDao = new UserDaoImpl();
return userDao.findByUsernameAndPassword(username, password);
}
}
// 服务类实现订单处理
public class OrderServiceImpl implements OrderService {
public boolean placeOrder(String serviceName, String serviceDate, String serviceTime, String address, String userId) {
OrderDao orderDao = new OrderDaoImpl();
return orderDao.insert(new Order(servic
评论已关闭