Java Web的简单登录应用
立即下载
资源介绍:
使用JavaWeb简单实现登录页面并分类跳转,使普通用户可以查看自己的有关数据,管理员身份登录可以对数据进行管理。(存在问题,求大佬指导)
package com.xxxx.controller;
import com.xxxx.entity.LotteryRecord;
import com.xxxx.service.LotteryRecordService;
import com.xxxx.mapper.LotteryMapperImpl;
import com.xxxx.mapper.LotteryRecordMapper;
import com.xxxx.util.MyBatisUtil;
import org.apache.ibatis.session.SqlSessionFactory;
import javax.servlet.RequestDispatcher;
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.util.List;
@WebServlet("/center")
public class LotteryRecordServlet extends HttpServlet {
public static int userId;
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
// 获取 SqlSessionFactory 实例
SqlSessionFactory sqlSessionFactory = MyBatisUtil.getSqlSessionFactory();
int userId = Integer.parseInt(req.getParameter("userId"));
// 创建 LotteryRecordMapperImpl 实例
LotteryRecordMapper mapper = new LotteryMapperImpl(sqlSessionFactory);
// 创建 LotteryRecordService 实例
LotteryRecordService service = new LotteryRecordService(mapper);
// 获取中奖记录
List records = service.getLotteryRecordsByUserId(userId);
// 将记录添加到请求属性
req.setAttribute("lotteryRecords", records);
// 转发到 JSP 页面
RequestDispatcher dispatcher = req.getRequestDispatcher("/center.jsp");
dispatcher.forward(req, resp);
}
}
资源文件列表:
loginProject.zip 大约有131个文件