本篇文章为你整理了08(08年北京奥运会)的详细内容,包含有08年的人今年多大了 08年北京奥运会 08年属什么生肖 08年汶川地震 08,希望能帮助你了解 08。
?xml version="1.0" encoding="UTF-8"?
web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
version="4.0"
!--项目默认打开的首页配置--
welcome-file-list
welcome-file login.jsp /welcome-file
/welcome-file-list
/web-app
project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
modelVersion 4.0.0 /modelVersion
groupId com.coolman /groupId
artifactId _03StudentManagerSystemBaseOnJSPAndTomcat /artifactId
version 1.0-SNAPSHOT /version
packaging war /packaging
properties
maven.compiler.source 8 /maven.compiler.source
maven.compiler.target 8 /maven.compiler.target
/properties
!-- 导入jar包--
dependencies
!-- 数据访问层
mysql:
mybatis:
Mybatis的日志配置
!--mysql--
dependency
groupId mysql /groupId
artifactId mysql-connector-java /artifactId
version 8.0.22 /version
/dependency
!-- mybatis --
dependency
groupId org.mybatis /groupId
artifactId mybatis /artifactId
version 3.5.5 /version
/dependency
!--MyBatis日志配置--
!-- 添加slf4j日志api --
dependency
groupId org.slf4j /groupId
artifactId slf4j-api /artifactId
version 1.7.20 /version
/dependency
!-- 添加logback-classic依赖 --
dependency
groupId ch.qos.logback /groupId
artifactId logback-classic /artifactId
version 1.2.3 /version
/dependency
!-- 添加logback-core依赖 --
dependency
groupId ch.qos.logback /groupId
artifactId logback-core /artifactId
version 1.2.3 /version
/dependency
逻辑业务层
servlet
jstl
!-- servlet --
dependency
groupId javax.servlet /groupId
artifactId javax.servlet-api /artifactId
version 3.1.0 /version
scope provided /scope
/dependency
!-- jsp --
dependency
groupId javax.servlet.jsp /groupId
artifactId jsp-api /artifactId
version 2.2 /version
scope provided /scope
/dependency
!-- jstl --
dependency
groupId jstl /groupId
artifactId jstl /artifactId
version 1.2 /version
/dependency
dependency
groupId commons-beanutils /groupId
artifactId commons-beanutils /artifactId
version 1.9.1 /version
/dependency
/dependencies
!-- tomcat7-maven-plugin插件 --
build
plugins
plugin
!--Maven直接启动Tomcat的插件--
groupId org.apache.tomcat.maven /groupId
artifactId tomcat7-maven-plugin /artifactId
version 2.2 /version
configuration
!--Tomcat7的插件的配置--
port 80 /port !--配置端口号--
path / /path !--配置项目路径--
!--Tomcat的get请求在8版本以下会出现中文乱码的问题,需要在这里配置--
uriEncoding UTF-8 /uriEncoding
/configuration
/plugin
/plugins
/build
/project
public String toString() {
return "User{id = " + id + ", name = " + name + ", phoneNumber = " + phoneNumber + ", password = " + password + "}";
public Student(int id, String stuNumber, String name, int age, String sex, double chineseScore, double mathScore, double englishScore) {
this.id = id;
this.stuNumber = stuNumber;
this.name = name;
this.age = age;
this.sex = sex;
this.chineseScore = chineseScore;
this.mathScore = mathScore;
this.englishScore = englishScore;
* 获取
* @return id
public int getId() {
return id;
* 设置
* @param id
public void setId(int id) {
this.id = id;
* 获取
* @return stuNumber
public String getStuNumber() {
return stuNumber;
* 设置
* @param stuNumber
public void setStuNumber(String stuNumber) {
this.stuNumber = stuNumber;
* 获取
* @return name
public String getName() {
return name;
* 设置
* @param name
public void setName(String name) {
this.name = name;
* 获取
* @return age
public int getAge() {
return age;
* 设置
* @param age
public void setAge(int age) {
this.age = age;
* 获取
* @return sex
public String getSex() {
return sex;
* 设置
* @param sex
public void setSex(String sex) {
this.sex = sex;
* 获取
* @return chineseScore
public double getChineseScore() {
return chineseScore;
* 设置
* @param chineseScore
public void setChineseScore(double chineseScore) {
this.chineseScore = chineseScore;
* 获取
* @return mathScore
public double getMathScore() {
return mathScore;
* 设置
* @param mathScore
public void setMathScore(double mathScore) {
this.mathScore = mathScore;
* 获取
* @return englishScore
public double getEnglishScore() {
return englishScore;
* 设置
* @param englishScore
public void setEnglishScore(double englishScore) {
this.englishScore = englishScore;
public String toString() {
return "Student{id = " + id + ", stuNumber = " + stuNumber + ", name = " + name + ", age = " + age + ", sex = " + sex + ", chineseScore = " + chineseScore + ", mathScore = " + mathScore + ", englishScore = " + englishScore + "}";
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import java.io.IOException;
import java.io.InputStream;
// 这是MyBatis的工具类,简化MyBatis代码
public class MyBatisUtils {
private static SqlSessionFactory sqlSessionFactory;
// 我们只需要一个SqlSessionFactory,在静态代码块中创建SqlSessionFactory
static {
try {
// 编写代码让MyBatis跑起来,执行SQL语句
String resource = "mybatis-config.xml";
// 加载核心配置文件
InputStream inputStream = Resources.getResourceAsStream(resource);
// 得到SqlSession工厂,赋值给成员变量
sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
} catch (IOException e) {
e.printStackTrace();
// 返回SqlSessionFactory
public static SqlSessionFactory getSqlSessionFactory() {
return sqlSessionFactory;
// 返回SqlSession
public static SqlSession openSession() {
return sqlSessionFactory.openSession();
public static SqlSession openSession(boolean autoCommit) {
return sqlSessionFactory.openSession(autoCommit);
用来生成验证码的工具类,其原理可以参考像关于Java的awt图像生成和验证码生成原理相关博客;(复制使用即可,原理不用深究)
private static final String VERIFY_CODES = "123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
private static Random random = new Random();
public static void main(String[] args) throws IOException {
FileOutputStream fos = new FileOutputStream("d:\\a.jpg");
String str = CheckCodeUtil.outputVerifyImage(100, 40, fos, 4);
System.out.println("str = " + str);
* 输出随机验证码图片流,并返回验证码值(一般传入输出流,响应response页面端,Web项目用的较多)
* @param width 图片宽度
* @param height 图片高度
* @param os 输出流
* @param verifySize 数据长度
* @return 验证码数据
* @throws IOException
public static String outputVerifyImage(int width, int height, OutputStream os, int verifySize) throws IOException {
String verifyCode = generateVerifyCode(verifySize);
outputImage(width, height, os, verifyCode);
return verifyCode;
* 使用系统默认字符源生成验证码
* @param verifySize 验证码长度
* @return
public static String generateVerifyCode(int verifySize) {
return generateVerifyCode(verifySize, VERIFY_CODES);
* 使用指定源生成验证码
* @param verifySize 验证码长度
* @param sources 验证码字符源
* @return
public static String generateVerifyCode(int verifySize, String sources) {
// 未设定展示源的字码,赋默认值大写字母+数字
if (sources == null sources.length() == 0) {
sources = VERIFY_CODES;
int codesLen = sources.length();
Random rand = new Random(System.currentTimeMillis());
StringBuilder verifyCode = new StringBuilder(verifySize);
for (int i = 0; i verifySize; i++) {
verifyCode.append(sources.charAt(rand.nextInt(codesLen - 1)));
return verifyCode.toString();
* 生成随机验证码文件,并返回验证码值 (生成图片形式,用的较少)
* @param w
* @param h
* @param outputFile
* @param verifySize
* @return
* @throws IOException
public static String outputVerifyImage(int w, int h, File outputFile, int verifySize) throws IOException {
String verifyCode = generateVerifyCode(verifySize);
outputImage(w, h, outputFile, verifyCode);
return verifyCode;
public static void outputImage(int w, int h, File outputFile, String code) throws IOException {
if (outputFile == null) {
return;
File dir = outputFile.getParentFile();
//文件不存在
if (!dir.exists()) {
//创建
dir.mkdirs();
try {
outputFile.createNewFile();
FileOutputStream fos = new FileOutputStream(outputFile);
outputImage(w, h, fos, code);
fos.close();
} catch (IOException e) {
throw e;
* 输出指定验证码图片流
* @param w
* @param h
* @param os
* @param code
* @throws IOException
public static void outputImage(int w, int h, OutputStream os, String code) throws IOException {
int verifySize = code.length();
BufferedImage image = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
Random rand = new Random();
Graphics2D g2 = image.createGraphics();
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
// 创建颜色集合,使用java.awt包下的类
Color[] colors = new Color[5];
Color[] colorSpaces = new Color[]{Color.WHITE, Color.CYAN,
Color.GRAY, Color.LIGHT_GRAY, Color.MAGENTA, Color.ORANGE,
Color.PINK, Color.YELLOW};
float[] fractions = new float[colors.length];
for (int i = 0; i colors.length; i++) {
colors[i] = colorSpaces[rand.nextInt(colorSpaces.length)];
fractions[i] = rand.nextFloat();
Arrays.sort(fractions);
// 设置边框色
g2.setColor(Color.GRAY);
g2.fillRect(0, 0, w, h);
Color c = getRandColor(200, 250);
// 设置背景色
g2.setColor(c);
g2.fillRect(0, 2, w, h - 4);
// 绘制干扰线
Random random = new Random();
// 设置线条的颜色
g2.setColor(getRandColor(160, 200));
for (int i = 0; i i++) {
int x = random.nextInt(w - 1);
int y = random.nextInt(h - 1);
int xl = random.nextInt(6) + 1;
int yl = random.nextInt(12) + 1;
g2.drawLine(x, y, x + xl + 40, y + yl + 20);
// 添加噪点
// 噪声率
float yawpRate = 0.05f;
int area = (int) (yawpRate * w * h);
for (int i = 0; i area; i++) {
int x = random.nextInt(w);
int y = random.nextInt(h);
// 获取随机颜色
int rgb = getRandomIntColor();
image.setRGB(x, y, rgb);
// 添加图片扭曲
shear(g2, w, h, c);
g2.setColor(getRandColor(100, 160));
int fontSize = h - 4;
Font font = new Font("Algerian", Font.ITALIC, fontSize);
g2.setFont(font);
char[] chars = code.toCharArray();
for (int i = 0; i verifySize; i++) {
AffineTransform affine = new AffineTransform();
affine.setToRotation(Math.PI / 4 * rand.nextDouble() * (rand.nextBoolean() ? 1 : -1), (w / verifySize) * i + fontSize / 2, h / 2);
g2.setTransform(affine);
g2.drawChars(chars, i, 1, ((w - 10) / verifySize) * i + 5, h / 2 + fontSize / 2 - 10);
g2.dispose();
ImageIO.write(image, "jpg", os);
* 随机颜色
* @param fc
* @param bc
* @return
private static Color getRandColor(int fc, int bc) {
if (fc 255) {
fc = 255;
if (bc 255) {
bc = 255;
int r = fc + random.nextInt(bc - fc);
int g = fc + random.nextInt(bc - fc);
int b = fc + random.nextInt(bc - fc);
return new Color(r, g, b);
private static int getRandomIntColor() {
int[] rgb = getRandomRgb();
int color = 0;
for (int c : rgb) {
color = color 8;
color = color c;
return color;
private static int[] getRandomRgb() {
int[] rgb = new int[3];
for (int i = 0; i i++) {
rgb[i] = random.nextInt(255);
return rgb;
private static void shear(Graphics g, int w1, int h1, Color color) {
shearX(g, w1, h1, color);
shearY(g, w1, h1, color);
private static void shearX(Graphics g, int w1, int h1, Color color) {
int period = random.nextInt(2);
boolean borderGap = true;
int frames = 1;
int phase = random.nextInt(2);
for (int i = 0; i i++) {
double d = (double) (period 1)
* Math.sin((double) i / (double) period
+ (6.2831853071795862D * (double) phase)
/ (double) frames);
g.copyArea(0, i, w1, 1, (int) d, 0);
if (borderGap) {
g.setColor(color);
g.drawLine((int) d, i, 0, i);
g.drawLine((int) d + w1, i, w1, i);
private static void shearY(Graphics g, int w1, int h1, Color color) {
int period = random.nextInt(40) + 10; // 50;
boolean borderGap = true;
int frames = 20;
int phase = 7;
for (int i = 0; i i++) {
double d = (double) (period 1)
* Math.sin((double) i / (double) period
+ (6.2831853071795862D * (double) phase)
/ (double) frames);
g.copyArea(i, 0, 1, h1, 0, (int) d);
if (borderGap) {
g.setColor(color);
g.drawLine(i, (int) d, i, 0);
g.drawLine(i, (int) d + h1, i, h1);
encoder
pattern [%level] %blue(%d{HH:mm:ss.SSS}) %cyan([%thread]) %boldGreen(%logger{15}) - %msg %n /pattern
/encoder
/appender
logger name="com.coolman" level="DEBUG" additivity="false"
appender-ref ref="Console"/
/logger
!--level:用来设置打印级别,大小写无关:TRACE, DEBUG, INFO, WARN, ERROR, ALL 和 OFF, 默认debug
root 可以包含零个或多个 appender-ref 元素,标识这个输出位置将会被本日志级别控制。--
root level="DEBUG"
appender-ref ref="Console"/
/root
/configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd"
configuration
settings
!-- 开启驼峰命名自动映射--
setting name="mapUnderscoreToCamelCase" value="true"/
/settings
!--起别名--
typeAliases
package name="com.coolman.pojo"/
/typeAliases
environments default="development"
environment id="development"
transactionManager type="JDBC"/
dataSource type="POOLED"
property name="driver" value="com.mysql.cj.jdbc.Driver"/
property name="url" value="jdbc:mysql://localhost:3306/sms?serverTimezone=Asia/Shanghai"/
property name="username" value="root"/
property name="password" value="123"/
/dataSource
/environment
/environments
mappers
!--扫描mapper--
package name="com.coolman.mapper"/
/mappers
/configuration
background-color: rgba(75, 81, 95, 0.3);
box-shadow: 7px 7px 17px rgba(52, 56, 66, 0.5);
border-radius: 5px;
#name_trip {
margin-left: 50px;
color: red;
margin-top: 30px;
margin-left: 20px;
color: azure;
font-size: 16px;
box-shadow: inset 0px 0px 10px rgba(255, 255, 255, 0.5), 0px 0px 15px rgba(75, 75, 75, 0.3);
text-align: left;
.form-div input[type="text"], .form-div input[type="password"], .form-div input[type="email"] {
width: 268px;
margin: 10px;
line-height: 20px;
font-size: 16px;
.form-div input[type="checkbox"] {
margin: 20px 0 20px 10px;
.form-div input[type="button"], .form-div input[type="submit"] {
margin: 10px 20px 0 0;
.form-div table {
margin: 0 auto;
text-align: right;
color: rgba(64, 64, 64, 1.00);
.form-div table img {
vertical-align: middle;
margin: 0 0 5px 0;
.footer {
color: rgba(64, 64, 64, 1.00);
font-size: 12px;
margin-top: 30px;
.form-div .buttons {
float: right;
input[type="text"], input[type="password"], input[type="email"] {
border-radius: 8px;
box-shadow: inset 0 2px 5px #eee;
padding: 10px;
border: 1px solid #D4D4D4;
color: #333333;
margin-top: 5px;
input[type="text"]:focus, input[type="password"]:focus, input[type="email"]:focus {
border: 1px solid #50afeb;
outline: none;
input[type="button"], input[type="submit"] {
padding: 7px 15px;
background-color: #3c6db0;
text-align: center;
border-radius: 5px;
overflow: hidden;
min-width: 80px;
border: none;
color: #FFF;
box-shadow: 1px 1px 1px rgba(75, 75, 75, 0.3);
input[type="button"]:hover, input[type="submit"]:hover {
background-color: #5a88c8;
input[type="button"]:active, input[type="submit"]:active {
background-color: #5a88c8;
.phone_number_err_msg{
color: red;
padding-right: 170px;
#password_err,#tel_err{
padding-right: 195px;
#reg_btn{
margin-right:50px; width: 285px; height: 45px; margin-top:20px;
#checkCode{
width: 100px;
#changeImg{
color: aqua;
%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %
%@ page contentType="text/html;charset=UTF-8" language="java" %
!DOCTYPE html
html lang="en"
head
meta charset="UTF-8"
title login /title
link href="css/login.css" rel="stylesheet"
/head
body
div id="loginDiv"
form action="loginServlet" method="post" id="form"
h1 id="loginMsg" 登 录 /h1
div id="errorMsg" ${loginMessage} ${registerMessage} /div
p 用户名: input id="phone_number" name="phone_number" type="text" value="${cookie.cookie_phone_number.value}" /p
p 密码: input id="password" name="password" type="password" value="${cookie.cookie_password.value}" /p
div
c:if test="${cookie.cookie_phone_number.value != null}"
p 记住我: input name="remember" type="checkbox" value="1" checked="checked" /p
/c:if
c:if test="${cookie.cookie_phone_number.value == null}"
p 记住我: input name="remember" type="checkbox" value="1" /p
/c:if
/div
div id="subDiv"
input type="submit" value="登 录"
input type="reset" value="reset" nbsp; nbsp; nbsp;
a href="register.jsp" 没有账号? /a
/div
/form
/div
/body
%-- script --%
%-- document.querySelectorAll(.inputs)[3].removeAttribute("check")--%
%-- /script --%
/html
input name="checkCode" type="text" id="checkCode"
img id="checkCodeImg" src="checkCodeServlet"
a href="#" id="changeImg" 看不清? /a
p align="left" id="checkCode_err"
${checkCode_err_msg}
/td
/tr
%-- tr --%
%-- td /td --%
%-- td align="center" id="checkCode_err" ${checkCode_err_msg} /td --%
%-- /tr --%
/table
div
input value="注 册" type="submit" id="reg_btn"
/div
/form
/div
script
// 点击换图片
document.getElementById("changeImg").onclick = function () {
let time = new Date().getTime();
// 找到img标签,更换src属性, 如果src相同,不会更换图片
document.getElementById("checkCodeImg").src = "checkCodeServlet?time=" + time;
/script
/body
/html
%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %
%@ page contentType="text/html;charset=UTF-8" language="java" %
!DOCTYPE html
html lang="en"
head
meta charset="UTF-8"
title Title /title
/head
body
h1 align="center" 欢迎您: ${username} 登录成功, 来到学生信息管理系统 /h1
table border="1" cellspacing="0" width="800" align="center"
th 序号 /th
th 学号 /th
th 姓名 /th
th 年龄 /th
th 性别 /th
th 语文成绩 /th
th 数学成绩 /th
th 英语成绩 /th
th 操作 /th
/tr
c:forEach items="${students}" var="student" varStatus="varSta"
tr align="center"
td ${varSta.count} /td
td ${student.stuNumber} /td
td ${student.name} /td
td ${student.age} /td
td ${student.sex} /td
td ${student.chineseScore} /td
td ${student.mathScore} /td
td ${student.englishScore} /td
td a href="updateBrand.jsp?id=${student.id}" 修改 /a a href="DeleteStudentByIdServlet?id=${student.id}" 删除 /a /td
/tr
/c:forEach
tr align="center"
td /td
td /td
td /td
td /td
td /td
td /td
td /td
td /td
td input type="button" value="新增学生信息" /td
/tr
/table
/body
/html
%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %
%@ page contentType="text/html;charset=UTF-8" language="java" %
html
head
title 修改品牌 /title
/head
body
String id = request.getParameter("id");
h3 修改品牌 /h3
form action="updateStudentByIdServlet" method="post"
div align="center"
input type="hidden" name="id" value=" %=id% "
span 学号: nbsp; nbsp; nbsp; nbsp; nbsp; nbsp; nbsp;
input name="stuNumber" br
/span
span 姓名: nbsp; nbsp; nbsp; nbsp; nbsp; nbsp; nbsp;
input name="name" br
/span
span 年龄: nbsp; nbsp; nbsp; nbsp; nbsp; nbsp; nbsp;
input name="age" br
/span
span 性别: nbsp; nbsp; nbsp; nbsp; nbsp; nbsp; nbsp;
input name="sex" br
/span
span 语文成绩:
input name="chineseScore" br
/span
span 数学成绩:
input name="mathScore" br
/span
span 英语成绩:
input name="englishScore" br
/span
input type="submit" value="提交"
/div
/form
/body
/html
public class LoginServlet extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request, response);
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// 在这里处理请求
// 获取登录页面POST请求传递回来的参数
String phoneNumber = request.getParameter("phone_number");
String password = request.getParameter("password");
String remember = request.getParameter("remember");
// 调用服务查询该用户是否存在
User user = new UserService().selectUserByPhoneNumberAndPassword(phoneNumber, password);
// 如果用户存在
if (user != null) {
// “记住我”功能
// 如果用户勾选了记住我,那么就将该数据存储至cookie中,交由客户端保存
Cookie phoneNumberCookie = new Cookie("cookie_phone_number", phoneNumber);
Cookie passwordCookie = new Cookie("cookie_password", password);
if ("1".equals(remember)) {
// 如果勾选
response.addCookie(phoneNumberCookie);
response.addCookie(passwordCookie);
System.out.println("用户勾选了“记住我”功能,并将数据保存到了cookie当中");
} else {
phoneNumberCookie.setMaxAge(0);
passwordCookie.setMaxAge(0);
response.addCookie(phoneNumberCookie);
response.addCookie(passwordCookie);
// 将用户信息存储在Session中,并跳转到信息展示列表页
HttpSession session = request.getSession();
session.setAttribute("username", user.getName());
// 跳转到信息展示列表页
response.sendRedirect("selectAllStudentsServlet");
} else {
// 如果用户不存在
// 提示错误信息
request.setAttribute("loginMessage", "用户名或者密码错误!");
// 请求转发重新回到登录界面
request.getRequestDispatcher("login.jsp").forward(request, response);
// 根据账号和密码查询用户
public User selectUserByPhoneNumberAndPassword(String phoneNumber, String password) {
SqlSession sqlSession = MyBatisUtils.openSession();
UserMapper mapper = sqlSession.getMapper(UserMapper.class);
User user = mapper.selectUserByPhoneNumberAndPassword(phoneNumber, password);
sqlSession.close();
return user;
// 根据账号和密码查询用户
@Select("select * from sms.user where phone_number = #{phoneNumber} and password = #{password};")
User selectUserByPhoneNumberAndPassword(@Param("phoneNumber") String phoneNumber, @Param("password") String password);
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
@WebServlet("/registerServlet")
public class RegisterServlet extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request, response);
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// 在这里处理请求
// 获取表单参数
String username = request.getParameter("username");
String phoneNumber = request.getParameter("phone_number");
String password = request.getParameter("password");
String checkCode = request.getParameter("checkCode");
// 获取正确的验证码
HttpSession session = request.getSession();
String correctCode = (String) session.getAttribute("correctCode");
// 判断phoneNumber是否唯一
// 查询数据库,调用服务
UserService service = new UserService();
User user = service.selectUserByPhoneNumber(phoneNumber);
if (user == null) {
// user 为空,说明不存在该用户,所以可以创建账号
// 调用服务,添加用户
// 判断验证码是否输入正确(忽略大小写)
if (correctCode.equalsIgnoreCase(checkCode)) {
// 如果验证码输入正确
// 调用服务,添加用户
service.addUser(new User(0, username, phoneNumber, password));
request.setAttribute("registerMessage", "注册成功,请登录");
request.getRequestDispatcher("login.jsp").forward(request, response);
} else {
// 如果输入错误
// 给出错误信息,验证码输入错误!
request.setAttribute("checkCode_err_msg", "验证码输入错误!");
request.getRequestDispatcher("register.jsp").forward(request, response);
} else {
// 给出错误信息:手机号码重复!
request.setAttribute("phone_number_err_msg", "手机号码重。
郑重声明:本文由网友发布,不代表盛行IT的观点,版权归原作者所有,仅为传播更多信息之目的,如有侵权请联系,我们将第一时间修改或删除,多谢。