第一步:数据库信息书写
#判断存在即删除数据库
drop database if exists mydb;
#创建数据库
create database mydb;
#使用数据库
use mydb;
#创建表
create table t_user
(
uid int primary key auto_increment,
username varchar(20),
password varchar(20),
phone varchar(11),
address varchar(50)
);
insert into t_user(username,password,phone,address) values('张三','666','18965423548','南阳');
insert into t_user(username,password,phone,address) values('李四','333','18754263548','许昌');
insert into t_user(username,password,phone,address) values('小美','123','18565234759','信阳');
select * from t_user where username=? and password=?
select * from t_user;
create table t_goods
(
gid int primary key auto_increment,
gname varchar(20),
price double,
mark varchar(100)
);
insert into t_goods(gname,price,mark) values('泡面',4.5,'够香够辣就是这个味!');
insert into t_goods(gname,price,mark) values('火腿',8.5,'肉质细腻Q弹!');
insert into t_goods(gname,price,mark) values('雪碧',3.5,'清爽冰凉随心爽!');
select * from t_goods;
![](https://img-blog.csdnimg.cn/img_convert/9e037362d95521de75a4910ccdcd783b.png)
![](https://img-blog.csdnimg.cn/img_convert/e1323dc65a4bfcccf9a188ca76d59177.png)
第二步:在web中书写HTML 页面 登录,错误页,主页,注册页
![](https://img-blog.csdnimg.cn/img_convert/f5b6f01ed7abefb2c02d1062f3afa2ca.png)
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>错误页</title>
</head>
<body>
<h1>出错啦</h1>
<a href="login.jsp">返回登录</a>
</body>
</html>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>这是第一个Web项目</title>
</head>
<body>
<h1>欢迎来到Web世界</h1>
<a href="login.jsp">去登录</a>
<a href="zhuce.jsp">去注册</a>
</body>
</html>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>登录</title>
</head>
<body>
<h1>登录</h1>
<form action="login" method="post">
账号:<input type="text" name="username"value=""/><br/>
密码:<input type="password" name="password"value=""/><br/>
<input type="submit" value="登录">
<a href="zhuce.jsp">没有帐号?请注册</a>
</form>
</body>
</html>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>注册</title>
</head>
<body>
<h1>注册</h1>
<form action="zhuce" method="post">
账号:<input type="t