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

📄 login.jsp

📁 大学JSP课程大作业
💻 JSP
字号:
<%@ page contentType="text/html; charset=gb2312"%>
<%@ page import="java.util.*" %>
<%@ page import="java.sql.*" %>
<%@ page import="my.shop.db.*" %>
<%@ page import="my.shop.vo.User" %>

<%
	String action = request.getParameter("action") ;
	//定义转发提示信息
	List msg = new ArrayList() ;
	if(!"".equals(action) && null != action && "login".equals(action)){	
		//表示由表单提交了数据,进行登录处理
		String username = request.getParameter("username") ;
		String userpwd  = request.getParameter("userpwd") ;
		if("".equals(username) || null==username){
			msg.add("用户名不能为空,请认真填写!");
		}else if("".equals(userpwd) || null==userpwd){
			msg.add("密码不能为空,请认真填写!");
		}else{
			//数据合法进行数据库验证
			String sql = "select * from manager where username=? and userpwd=?" ;
			Connection conn = DBConnection.getInstance().getConnection() ;
			PreparedStatement pstmt = conn.prepareStatement(sql) ;
			pstmt.setString(1,username) ;
			pstmt.setString(2,userpwd) ;
			ResultSet rs = pstmt.executeQuery() ;
			if(rs.next()){
				//验证成功,取得用户所有信息
				User user = new User() ; 
				user.setId(rs.getInt(1)) ;
				user.setUsername(rs.getString(2)) ;
				user.setUserpwd(rs.getString(3)) ;
				user.setName(rs.getString(4)) ;
				user.setAddress(rs.getString(5)) ;
				user.setMail(rs.getString(6)) ;
				user.setPhone(rs.getString(7)) ;
				session.setAttribute("manageruser",user) ;
				rs.close() ;
				pstmt.close() ;
				conn.close() ;
				response.sendRedirect("admin.jsp") ;
			}else{
				//验证失败,重新进行登录
				msg.add("您输入的用户名或密码错误,请重试") ;
			}
		}
	}
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>后台管理员登录</title>
<style type="text/css">
<!--
.STYLE1 {
	font-size: 24px;
	font-weight: bold;
}
-->
</style>
</head>

<body>
<table width="1024" border="0" align="center">
  <tr>
    <th height="101" align="center"><div align="center" class="STYLE1">购物网站后台管理</div></th>
  </tr>
</table><hr>
<form action="login.jsp" method="post">
<input type="hidden" name="action" value="login">
<table width="302" height="125" border="0" align="center">
  <tr>
    <td height="26" colspan="5" bgcolor="#3366CC"><div align="center"><span class="STYLE1">管理员登录</span></div></td>
  </tr>
  <tr>
    <td height="24" bgcolor="#899BE4">用户名:</td>
    <td colspan="2" bgcolor="#899BE4"><input type="text" name="username"/></td>
  </tr>
  <tr>
    <td height="25" bgcolor="#899BE4">密&nbsp;&nbsp;码:</td>
    <td colspan="2" bgcolor="#899BE4"><input type="password" name="userpwd" /></td>
  </tr>
  <tr>
    <td height="23" bgcolor="#899BE4" align="right">

    </td>
    <td bgcolor="#899BE4"><input type="submit" value="登录" /></td>
    </tr>
</table>
</form>
<%
	if(null != msg && msg.size() > 0){
		for(Iterator it = msg.iterator();it.hasNext();){
			String m = (String)it.next() ;
%>
			<div align="center"><font color=red ><%= m %></font></div><br>
<%
		}
	}
%>
</body>
</html>

⌨️ 快捷键说明

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