⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 registermanage.jsp

📁 某电子商品销售公司为了提升企业形象和商品销售量
💻 JSP
字号:
<%@page import="s2jsp.bysj.dao.UserDao"%>
<%@ page language="java" import="java.util.*,s2jsp.bysj.entity.Users"
	pageEncoding="gbk"%>
<%
	String userName = request.getParameter("userName");
	String password = request.getParameter("password");
	String param = request.getParameter("param");//获取param参数,用以判断用户操作是注册还是登录

	UserDao userDao = new UserDao();
	//判断用户输入信息是否为空
	if (param == null || userName == null || password == null) {
		response.sendRedirect("register.jsp");
	} else if (param != null && "login".equals(param)) {  //登录操作
		//根据用户名和密码查询数据库
		Users user = userDao.findUsers(userName, password);
		if (user != null) {		//判断当前用户是否存在	
			//如果用户存在,把当前用户名保存到application中的List集合内
			List userList = (List) application.getAttribute("users");
			if (userList == null || userList.size() == 0) {  //针对第一个登录用户的操作
				userList = new ArrayList();
				userList.add(userName);
			} else {   //针对其他用户的操作
				boolean bool = true;
				for (int i = 0; i < userList.size(); i++) {
		
					if (userName.equals(userList.get(i).toString())) {
						bool = false;
						break;
					}
				}
				if (bool)
					userList.add(userName);
			}
			//把当前用户的信息保存到session中
			session.setAttribute("user", user);
			application.setAttribute("users", userList);
			response.sendRedirect("main.jsp");
		} else{   //如果用户不存在,给出提示后,返回到网站首页
			//response.sendRedirect("register.jsp");
			out
			.print("<script type='text/javascript'>alert('用户名或密码错误,请重新登录。');location.replace('index.jsp');</script>");
		}
	} else {  //注册操作
		int count = userDao.insertUser(userName, password,0);
		if (count > 0) {
			out
			.print("<script type='text/javascript'>alert('注册成功,请登录。');location.replace('index.jsp');</script>");
		} else {
			out
			.print("<script type='text/javascript'>alert('注册失败,请重新注册。');history.go(-1);</script>");
		}
	}
%>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -