1, and set up your database
1, there is a user table, used to store your user information
Fields: id, username, password table name: user
2, there is a student table
Fields: id, name, age, sex, gid, city table name: student
A: environmental structures
1, first create a web project
2, the lib packages under your webroot under web-inf in the jar you use to pack into them
3, you need it on your three-tier architecture to break out of the pack
dao package which put our interface data (model)
entity put the package entity classes (javaBean)
Servlet package is put inside (servlet --- is our controller controller)
util bag contains is (are put tools, ConfigManager, basedao: our jdbc wrapper class)
4, we also need a package, which is parallel to your project and resource pack this bag contains a connection to the database configuration file
We set up this project completed
The first module: Registration
1, we have a registration page
Ideas: the registration information submitted to the servlet inside the servlet our information stored in the database
1, registration information to spread to the servlet
2, we write a servlet to get the value on the page
Instantiate your interface classes, call interface implementation class method
Remember: call access and method of the servlet only data pages Jump
3, registration interface
public int regin(String name,String password);
4, the interface implementation class: inherit your basedao achieve your interface
Interface class just need to write a sql statement
Call our basedao the executeUpdate method (add, modify, delete all call executeUpdate)
Remember: the interface implementation class is written inside all of our business logic
The second module: landing
1, we have a landing jsp (servlet jump from registration of your landing page)
<form name="form1" method="post" action="LoginServlet">
用户名: <input type="text" name="username">
密码: <input type="password" name="password">
<input type="submit" value="登录">
</form>
2、我们在登陆页面中提交到我们的登陆的srvlet中(LoginServlet)
3、我们需要创建一个Loginservlet
登陆的思路:拿到用户名和密码去你的数据库中进行查询,查询出这个数据,证明登陆成功否者登陆失败
获取登陆的用户名和密码
实例化登陆接口实现类
调用登陆方法
如果登陆成功了{
我们要吧列表上的数据查询出来(查询出Student表中所有的数据)
}
4、要写一个接口
public ResultSet login(String name,String password);
//列表中的接口:查询学生表中所有的信息
public ResultSet finduser();
5、写一个接口实现类
写一条sql调用basedao中的executequery()
登陆的方法
查询出列表的方法(查询student表中的方法)
6、我们需要创建一个学生表的实体类StudentEntity