环境搭建及资源参照B站狂神说JavaWeb视频。
实现功能:
首先进入登录界面login.jsp
可通过在web.xml进行如下设置实现:
如果用户名和密码正确则进入frame.jsp界面:
如果用户名和密码不正确则进入登录界面login.jsp,并提示错误信息:
login.jsp:
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%><html><head lang="en"> <meta charset="UTF-8"> <title>系统登录 - 超市订单管理系统title> <link type="text/css" rel="stylesheet" href="${pageContext.request.contextPath }/css/style.css" /> <script type="text/javascript"> /* if(top.location!=self.location){
top.location=self.location; } */script>head><body class="login_bg"> <section class="loginBox"> <header class="loginHeader"> <h1>超市订单管理系统h1> header> <section class="loginCont"> <form class="loginForm" action="${pageContext.request.contextPath }/login.do" name="actionForm" id="actionForm" method="post" > <div class="info">${error}div> <div class="inputbox"> <label>用户名:label> <input type="text" class="input-text" id="userCode" name="userCode" placeholder="请输入用户名" required/> div> <div class="inputbox"> <label>密码:label> <input type="password" id="userPassword" name="userPassword" placeholder="请输入密码" required/> div> <div class="subBtn"> <input type="submit" value="登录"/> <input type="reset" value="重置"/> div> form> section> section>body>html>
error.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%><html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>Insert title heretitle>head><body><h1>请登录后再访问该页面!h1><a href="login.jsp">返回a>body>html>
1 搭建数据库
resources目录下db.properties文件
driver=com.mysql.jdbc.Driver#在和mysql传递数据的过程中,使用unicode编码格式,并且字符集设置为utf-8url=jdbc:mysql://localhost:3306/smbms?useUnicode=true&useSSL=false&characterEncoding=utf-8user=rootpassword=root
2 建包目录如下
pojo
数据关系映射
User
package com.zhu.pojo;import java.util.Date;public class User {
private Integer id; //id private String userCode; //用户编码 private String use