1.建库,建表2个
用户表(id,用户名,密码)
邮件表(id,发件人,收件人,标题,内容,发送时间,状态)

2.建model层
entity,dao包

3.登陆,注册,登陆后显示全部邮件

dao

 1 package com.gd.dao;
2
3 import java.sql.Connection;
4 import java.sql.DriverManager;
5 import java.sql.PreparedStatement;
6 import java.sql.ResultSet;
7 import java.sql.SQLException;
8
9 public class BaseDao {
10 // 获取连接
11 protected Connection getConnection() {
12 Connection conn = null;
13 try {
14 Class.forName("com.mysql.jdbc.Driver");
15 // 2.建立连接
16 conn = DriverManager.getConnection(
17 "jdbc:mysql://localhost:3306/test", "root", "123456");
18 } catch (Exception e) {
19 e.printStackTrace();
20 }
21 return conn;
22 }
23
24 // 关闭连接
25 protected void closeAll(Connection con, PreparedStatement ps, ResultSet rs) {
26 try {
27 if (rs != null)
28 rs.close();
29 if (ps != null)
30 ps.close();
31 if (con != null)
32 con.close();
33
34 } catch (SQLException e) {
35 e.printStackTrace();
36 }
37 }
38 }
 1 package com.gd.dao;
2
3 import java.sql.Connection;
4 import java.sql.PreparedStatement;
5 import java.sql.ResultSet;
6 import java.sql.SQLException;
7 import java.util.ArrayList;
8 import java.util.List;
9
10 import com.gd.entity.Msg;
11
12 public class MsgDao extends BaseDao {
13 public List<Msg> listAll(String username) throws SQLException{
14 List<Msg> list =new ArrayList<Msg>();
15 Connection conn =getConnection();
16 String sql="select * from msg where username=?";
17 PreparedStatement pred =null;
18
19 ResultSet rest=null;
20 try {
21 pred=conn.prepareStatement(sql);
22 pred.setString(1, username);
23 rest=pred.executeQuery();
24 while (rest.next()) {
25 Msg msg=new Msg();
26 msg.setMsgid(rest.getInt("msgid"));
27 msg.setUsername(rest.getString("username"));
28 msg.setTitle(rest.getString("title"));
29 msg.setMsgcontent(rest.getString("msgcontent"));
30 msg.setState(rest.getInt("state"));
31 msg.setSendto(rest.getString("sendto"));
32 msg.setMsg_create_date(rest.getDate("msg_create_date"));
33 list.add(msg);
34 }
35 } catch (Exception e) {
36 // TODO: handle exception
37 }
38 finally{
39 closeAll(conn, pred, rest);
40 }
41 return list;
42 }
43
44 }
 1 package com.gd.dao;
2
3 import java.sql.Connection;
4 import java.sql.PreparedStatement;
5 import java.sql.ResultSet;
6 import java.sql.SQLException;
7
8 public class UsersDao extends BaseDao {
9 public boolean login(String uname, String upwd) throws SQLException {
10 boolean f = false;
11 Connection conn = getConnection();
12 PreparedStatement pred = null;
13 ResultSet rest = null;
14 String sql = "select * from users where uname=? and upwd=?";
15 try {
16 pred = conn.prepareStatement(sql);
17 pred.setString(1, uname);
18 pred.setString(2, upwd);
19 rest = pred.executeQuery();
20 while (rest.next()) {
21 f = true;
22 }
23 } catch (Exception e) {
24 // TODO: handle exception
25 } finally {
26 closeAll(conn, pred, rest);
27 }
28 return f;
29 }
30
31 public boolean id(Integer id) throws SQLException {
32 boolean f = false;
33 Connection conn = getConnection();
34 PreparedStatement pred = null;
35 ResultSet rest = null;
36 String sql = "select * from users where id=?";
37 try {
38 pred = conn.prepareStatement(sql);
39 pred.setInt(1, id);
40 rest = pred.executeQuery();
41 while (rest.next()) {
42 f = true;
43 }
44 } catch (Exception e) {
45 // TODO: handle exception
46 } finally {
47 closeAll(conn, pred, rest);
48 }
49 return f;
50 }
51
52 public void zhuce(Integer id, String uname, String upwd) {
53 Connection conn = getConnection();
54 PreparedStatement pred = null;
55 try {
56 String sql = "insert into users(id,uname,upwd) values(?,?,?)";
57 pred = conn.prepareStatement(sql);
58 pred.setInt(1, id);
59 pred.setString(2, uname);
60 pred.setString(3, upwd);
61 pred.executeUpdate();
62
63 } catch (Exception e) {
64 // TODO: handle exception
65 } finally {
66 closeAll(conn, pred, null);
67 }
68 }
69
70 }

entity

 1 package com.gd.entity;
2
3 import java.util.Date;
4
5 public class Msg {
6 private Integer msgid;
7 private String username;
8 private String title;
9 private String msgcontent;
10 private Integer state;
11 private String sendto;
12 private Date msg_create_date;
13
14 public Integer getMsgid() {
15 return msgid;
16 }
17 public void setMsgid(Integer msgid) {
18 this.msgid = msgid;
19 }
20 public String getUsername() {
21 return username;
22 }
23 public void setUsername(String username) {
24 this.username = username;
25 }
26 public String getTitle() {
27 return title;
28 }
29 public void setTitle(String title) {
30 this.title = title;
31 }
32 public String getMsgcontent() {
33 return msgcontent;
34 }
35 public void setMsgcontent(String msgcontent) {
36 this.msgcontent = msgcontent;
37 }
38 public Integer getState() {
39 return state;
40 }
41 public void setState(Integer state) {
42 this.state = state;
43 }
44 public String getSendto() {
45 return sendto;
46 }
47 public void setSendto(String sendto) {
48 this.sendto = sendto;
49 }
50 public Date getMsg_create_date() {
51 return msg_create_date;
52 }
53 public void setMsg_create_date(Date msg_create_date) {
54 this.msg_create_date = msg_create_date;
55 }
56
57 }
 1 package com.gd.entity;
2
3 public class Users {
4 private Integer id;
5 private String uname;
6 private String upwd;
7 public Integer getId() {
8 return id;
9 }
10 public void setId(Integer id) {
11 this.id = id;
12 }
13 public String getUname() {
14 return uname;
15 }
16 public void setUname(String uname) {
17 this.uname = uname;
18 }
19 public String getUpwd() {
20 return upwd;
21 }
22 public void setUpwd(String upwd) {
23 this.upwd = upwd;
24 }
25
26
27 }

jsp

 1 <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
2 <%
3 request.setCharacterEncoding("utf-8");
4 response.setCharacterEncoding("utf-8");
5 %>
6 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
7 <html>
8 <head>
9 <title>My JSP 'zhuce.jsp' starting page</title>
10 </head>
11 <body>
12 <script type="text/javascript">
13 function dozhuce() {
14 if (loginform2.id.value == "") {
15 alert("没有输入id");
16 return;
17 }
18 if (loginform2.uname.value == "") {
19 alert("没有输入用户名");
20 return;
21 }
22 if (loginform2.upwd.value == "") {
23 alert("没有输入密码");
24 return;
25 }
26 if (loginform2.upwd2.value == "") {
27 alert("没有确认密码");
28 return;
29 }
30 loginform2.submit();
31 }
32 </script>
33 <form action="dozhuce.jsp" name="loginform2" method="post">
34 id: <input type="number" name="id" /><br>
35 用户名:<input type="text" name="uname" /> <br>
36 密码:<input type="password" name="upwd" /> <br>
37 确认密码:<input type="password" name="upwd2" /><br>
38 <input type="button" value="注册" onclick="dozhuce()" />
39 </form>
40 </body>
41 </html>
 1 <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
2 <%@page import="com.gd.dao.UsersDao"%>
3 <%
4 request.setCharacterEncoding("utf-8");
5 response.setCharacterEncoding("utf-8");
6 %>
7 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
8 <html>
9 <head>
10 <title>My JSP 'dozhuce.jsp' starting page</title>
11 </head>
12 <body>
13 <%
14 String uid = request.getParameter("id");
15 Integer id = Integer.parseInt(uid);
16 String uname = request.getParameter("uname");
17 String upwd = request.getParameter("upwd");
18 String upwd2 = request.getParameter("upwd2");
19 UsersDao usersDao = new UsersDao();
20 if (upwd.equals(upwd2)) {
21 if (usersDao.id(id)) {
22 out.print("已经有这个id了,即将跳回注册页.....");
23 response.setHeader("refresh", "5;url=zhuce.jsp");
24 } else {
25 usersDao.zhuce(id, uname, upwd);
26 out.print("注册成功,即将跳回登录页.....");
27 response.setHeader("refresh", "5;url=login.jsp");
28 }
29 } else {
30 out.print("两次密码不一致,即将跳回注册页.....");
31 response.setHeader("refresh", "5;url=zhuce.jsp");
32 }
33 %>
34 </body>
35 </html>
 1 <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
2 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
3 <html>
4 <head>
5 <title>My JSP 'login.jsp' starting page</title>
6 </head>
7
8 <body>
9 <script type="text/javascript">
10 function dologin() {
11 if (loginform.uname.value == "") {
12 alert("没有输入用户名");
13 return;
14 }
15 if (loginform.upwd.value == "") {
16 alert("没有输入密码");
17 return;
18 }
19 loginform.submit();
20 }
21 </script>
22 <form action="dologin.jsp" name="loginform" method="post">
23 用户名:<input type="text" name="uname" /> <br>
24 密码:<input type="password" name="upwd" /> <br>
25 <input type="button" value="登录" onclick="dologin()" />
26 <a href="zhuce.jsp">没有账号?立即注册</a>
27 </form>
28 </body>
29 </html>
 1 <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
2 <%@page import="sun.security.jgss.LoginConfigImpl"%>
3 <%@page import="com.gd.dao.UsersDao"%>
4 <%
5 request.setCharacterEncoding("utf-8");
6 response.setCharacterEncoding("utf-8");
7 %>
8 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
9 <html>
10 <head>
11 <title>My JSP 'dologin.jsp' starting page</title>
12 </head>
13
14 <body>
15 <%
16 String uname = request.getParameter("uname");
17 String upwd = request.getParameter("upwd");
18 UsersDao ud = new UsersDao();
19 if (ud.login(uname, upwd)) {
20 session.setAttribute("uname", uname);
21 request.getRequestDispatcher("index.jsp").forward(request,
22 response);
23 } else {
24 out.print("登录失败,5s后跳转登录页面");
25 response.setHeader("refresh", "5;url=login.jsp");
26 }
27 %>
28 </body>
29 </html>
  1 <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
2 <%@page import="java.util.List"%>
3 <%@page import="com.gd.dao.MsgDao"%>
4 <%@page import="com.gd.entity.Msg"%>
5 <%@page import="sun.security.jgss.LoginConfigImpl"%>
6 <%@page import="com.gd.dao.UsersDao"%>
7 <%
8 request.setCharacterEncoding("utf-8");
9 response.setCharacterEncoding("utf-8");
10 %>
11 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
12 <html>
13 <head>
14 <title>My JSP 'index.jsp' starting page</title>
15 </head>
16 <body>
17 <%
18 String uname = (String) session.getAttribute("uname");
19 if (uname == null) {
20 out.print("您未登录,即将跳回登陆页.....");
21 response.setHeader("refresh", "5;url=login.jsp");
22 } else {
23 %>
24 欢迎你<%=uname%>
25
26
27
28 <%
29 Msg msg = new Msg();
30 MsgDao msgDao = new MsgDao();
31 List<Msg> list = new ArrayList<Msg>();
32 list = msgDao.listAll(uname);
33 %>
34 邮件列表:
35 <table width="600px" border="2px solid blue">
36 <tr>
37 <th>id</th>
38 <th>发件人</th>
39 <th>标题</th>
40 <th>内容</th>
41 <th>已读未读状态</th>
42 <th>收件人</th>
43 <th>发送时间</th>
44 </tr>
45 <%
46 if (list.size() == 0) {
47 out.print("你没有邮件");
48 } else {
49 for (Msg msg1 : list) {
50 %>
51 <tr>
52 <td>
53 <%
54 out.print(msg1.getMsgid());
55 %>
56 </td>
57 <td>
58 <%
59 out.print(msg1.getUsername());
60 %>
61 </td>
62 <td>
63 <%
64 out.print(msg1.getTitle());
65 %>
66 </td>
67 <td>
68 <%
69 out.print(msg1.getMsgcontent());
70 %>
71 </td>
72 <td>
73 <%
74 int state = msg1.getState();
75 if (state == 1) {
76 %> <img src="data:image/yidu.png" /> <%
77 ;
78 } else {
79 %> <img src="data:image/weidu.png" /> <%
80 ;
81 }
82 %>
83 </td>
84 <td>
85 <%
86 out.print(msg1.getSendto());
87 %>
88 </td>
89 <td>
90 <%
91 out.print(msg1.getMsg_create_date());
92 %>
93 </td>
94 </tr>
95 <%
96 }
97 }
98 }
99 %>
100 </table>
101 </body>
102 </html>

搜索

复制

JSP第九次作业的更多相关文章

  1. JAVA第九次作业

    JAVA第九次作业 (一)学习总结 1.用思维导图对javaIO操作的学习内容进行总结. 参考资料: XMind. 2.下面的程序实现了文件的拷贝,但采用的是一个字节一个字节的读写方式,效率很低.使用 ...

  2. 2018-2019-1 20189221 《Linux内核原理与分析》第九周作业

    2018-2019-1 20189221 <Linux内核原理与分析>第九周作业 实验八 理理解进程调度时机跟踪分析进程调度与进程切换的过程 进程调度 进度调度时机: 1.中断处理过程(包 ...

  3. 2017-2018-2 1723《程序设计与数据结构》第九周作业 & 第二周结对编程 总结

    作业地址 第九次作业:https://edu.cnblogs.com/campus/besti/CS-IMIS-1723/homework/1878 (作业界面已评分,可随时查看,如果对自己的评分有意 ...

  4. C#基础第九天-作业答案-储蓄账户(SavingAccount)和信用账户(CreditAccount)

    class Bank { //Dictionary<long,Account> dictionary=new Dictionary<long,Account>(); DataT ...

  5. C#基础第九天-作业-储蓄账户(SavingAccount)和信用账户(CreditAccount)

    要求1:完成以下两种账户类型的编码.银行的客户分为两大类:储蓄账户(SavingAccount)和信用账户(CreditAccount),两种的账户类型的区别在于:储蓄账户不允许透支,而信用账户可以透 ...

  6. Jsp实现在线作业提交系统

    Jsp实现在线作业提交系统 作为 Computer Science 的学生,凌晨四点之前睡都应该感到羞耻. 项目托管地址:https://github.com/four-in-the-morning/ ...

  7. Week09《java程序设计》第九次作业总结

    Week09<java程序设计>第九次作业总结 1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结集合与泛型相关内容. 答: 2. 书面作业 本次作业题集集合 1. Li ...

  8. 2017-2018-1 20179205《Linux内核原理与设计》第九周作业

    <Linux内核原理与设计>第九周作业 视频学习及代码分析 一.进程调度时机与进程的切换 不同类型的进程有不同的调度需求,第一种分类:I/O-bound 会频繁的进程I/O,通常会花费很多 ...

  9. 【西北师大-2108Java】第九次作业成绩汇总

    [西北师大-2108Java]第九次作业成绩汇总 作业题目 面向对象程序设计(JAVA) 第11周学习指导及要求 实验目的与要求 (1)理解泛型概念: (2)掌握泛型类的定义与使用: (3)掌握泛型方 ...

  10. “希希敬敬对”队软件工程第九次作业-beta冲刺第五次随笔

    “希希敬敬对”队软件工程第九次作业-beta冲刺第五次随笔 队名:  “希希敬敬对” 龙江腾(队长) 201810775001 杨希                   201810812008 何敬 ...

随机推荐

  1. 如何在JavaScript中使用for循环

    前言 循环允许我们通过循环数组或对象中的项并做一些事情,比如说打印它们,修改它们,或执行其他类型的任务或动作.JavaScript有各种各样的循环,for循环允许我们对一个集合(如数组)进行迭代. 在 ...

  2. K8s如何启用cgroup2支持?

    什么是 cgroup ️Reference: control groups(控制组),通常被称为cgroup,是Linux内核的一项功能.它允许将进程组织成分层的组,然后限制和监控各种资源的使用. 内 ...

  3. webrtc编译,不使用内置boringssl,使用openssl的

    前言 在项目开发过程中,会遇到使用https.TLS.DTLS等场景,这些第三方库一般会使用openssl作为加密套件.例如,qt中加密套件就会使用openssl,但是webrtc会默认使用borin ...

  4. 总结uni-app遇到的坑持续跟新

    1.uni.navigateTo跳转没有反应 官方示例 //在起始页面跳转到test.vue页面并传递参数 uni.navigateTo({ url: 'test?id=1&name=unia ...

  5. adb版本不同导致一个服务杀死另一个服务

    前言 由于我用安装模拟器进行调试app,需要连接到固定端口, 而开发测试的时候用到eclipse中调用sdk中包含一个版本的adb, 另外Android killer中也包含一个版本的adb, 另外我 ...

  6. javaweb string

    今天遇到一个跨域请求jsonp格式报错,其原因是其中一个参数过从我方数据库取出就带有换行格式的,类似于: 这条数据竟然自带格式换行. 而我们现常用的trim()只能去掉字符串的头部和尾部的空格, 而要 ...

  7. .net如何优雅的使用EFCore

    EFCore是微软官方的一款ORM框架,主要是用于实体和数据库对象之间的操作.功能非常强大,在老版本的时候叫做EF,后来.net core问世,EFCore也随之问世. 本文我们将用一个控制台项目Ho ...

  8. 【SQL基础】【关键字大写】条件查询:比较、不等于、IN、为空、BETWEEN

    〇.概述 1.内容介绍 条件查询:比较.不等于.IN.为空.BETWEEN 2.建表语句 drop table if exists user_profile; CREATE TABLE `user_p ...

  9. SQL语句筛选/查询

    目录 SQL语句查询关键词 查询关键字之where筛选 查询关键字之分组 group by Group_concat 方法 查询关键字之having过滤 查询关键字之去重distinct 关键字之or ...

  10. [FCC] Cash Register 计算找零

    题目地址: https://chinese.freecodecamp.org/learn/javascript-algorithms-and-data-structures/javascript-al ...