jsp第七次作业

<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>登录</title>
</head>
<body>
    <form action="dologin.jsp" method="post">
        用户名:<input type="text" name="username" value="yxy" /><Br> 密码 :<input
            type="password" name="password" value="123456" /><br> <input
            type="submit" value="登录">

    </form>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
    <%
    request.setCharacterEncoding("utf-8");
    String u = request.getParameter("username");
    String p = request.getParameter("password");
    if (u.equals("yxy")&&p.equals("123456")) {
        request.getRequestDispatcher("index.jsp").forward(request, response);
    } else {
        response.sendRedirect("login.jsp");
    }
    %>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
    <%
    request.setCharacterEncoding("utf-8");
    String u = request.getParameter("username");
    String p = request.getParameter("password");
    if (u.equals("yxy")&&p.equals("123456")) {
        request.getRequestDispatcher("index.jsp").forward(request, response);
    } else {
        response.sendRedirect("login.jsp");
    }
    %>
</body>
</html>
<body>
    <%
        request.setCharacterEncoding("utf-8");
        String uname = (String) session.getAttribute("username");
        String newstate = null;
        //获取邮件列表页面输入的标题
        String contitle = request.getParameter("contitle");
        Connection conn = null;
        PreparedStatement ps = null;
        ResultSet rs = null;
        try {
            Class.forName("com.mysql.jdbc.Driver");
            //加载驱动
            String url = "jdbc:mysql://localhost:3306/mydb";
            String user = "root";
            String password = "root";
            conn = DriverManager.getConnection(url, user, password);
            // 连接对象
            //conn = BaseDao.getConnection();
    %>
    <%
        Msg msg = new Msg();
            ps = conn.prepareStatement("select * from msg where title=?and username=?");
            ps.setString(1, contitle);
            ps.setString(2, uname);
            rs = ps.executeQuery();
            while (rs.next()) {
    %>

    <form action="" name="huifu" method="post">
        sendto &nbsp;<%=rs.getString("sendto")%><br> <br>标题:<%=rs.getString("title")%><br>
        <br> 正文:<%=rs.getString("msgcontent")%><br>
        <%
            //更新阅读状态
                    if (rs.getInt("state") == 1) {
                        ps = conn.prepareStatement("update msg set state=? where state=? and title=?");
                        // 执行sql语句
                        ps.setInt(1, 0);
                        ps.setInt(2, 1);
                        ps.setString(3, contitle);
                        ps.executeUpdate();

                        break;
                    }
        %>
        <%
            }
        %>



    </form>
    <form action="insert.jsp" method="post">
        <%
            session.setAttribute("uuname", uname);
            session.setAttribute("newcontitle", contitle);
        %><input type="submit" value="回复">&nbsp;
    </form>
    <form action="main2.jsp" method="post">
        <%
            session.setAttribute("uuname", uname);
        %>
        <input type="submit" value="返回邮件列表" name="newyjlb">
    </form>
    <form action="delete.jsp" method="post">
        <%
            session.setAttribute("uuname", uname);
                session.setAttribute("newcontitle", contitle);
        %>
        <input type="submit" value="删除邮件" name="deleteyj">
    </form>



    <%
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            //BaseDao.closeAll(conn, ps, rs);
            try {
                if (rs != null) {
                    rs.close();
                }
            } finally {
                try {
                    if (ps != null) {
                        ps.close();
                    }
                } finally {
                    if (conn != null) {
                        conn.close();
                    }
                }
            }
        }
    %>

</body>
<body>
    <%
        request.setCharacterEncoding("utf-8");
        String uname = (String) session.getAttribute("username");
        String newstate = null;
        //获取邮件列表页面输入的标题
        String contitle = request.getParameter("contitle");
        Connection conn = null;
        PreparedStatement ps = null;
        ResultSet rs = null;
        try {
            Class.forName("com.mysql.jdbc.Driver");
            //加载驱动
            String url = "jdbc:mysql://localhost:3306/mydb";
            String user = "root";
            String password = "root";
            conn = DriverManager.getConnection(url, user, password);
            // 连接对象
            //conn = BaseDao.getConnection();
    %>
    <%
        Msg msg = new Msg();
            ps = conn.prepareStatement("select * from msg where title=?and username=?");
            ps.setString(1, contitle);
            ps.setString(2, uname);
            rs = ps.executeQuery();
            while (rs.next()) {
    %>

    <form action="" name="huifu" method="post">
        sendto &nbsp;<%=rs.getString("sendto")%><br> <br>标题:<%=rs.getString("title")%><br>
        <br> 正文:<%=rs.getString("msgcontent")%><br>
        <%
            //更新阅读状态
                    if (rs.getInt("state") == 1) {
                        ps = conn.prepareStatement("update msg set state=? where state=? and title=?");
                        // 执行sql语句
                        ps.setInt(1, 0);
                        ps.setInt(2, 1);
                        ps.setString(3, contitle);
                        ps.executeUpdate();

                        break;
                    }
        %>
        <%
            }
        %>



    </form>
    <form action="insert.jsp" method="post">
        <%
            session.setAttribute("uuname", uname);
            session.setAttribute("newcontitle", contitle);
        %><input type="submit" value="回复">&nbsp;
    </form>
    <form action="main2.jsp" method="post">
        <%
            session.setAttribute("uuname", uname);
        %>
        <input type="submit" value="返回邮件列表" name="newyjlb">
    </form>
    <form action="delete.jsp" method="post">
        <%
            session.setAttribute("uuname", uname);
                session.setAttribute("newcontitle", contitle);
        %>
        <input type="submit" value="删除邮件" name="deleteyj">
    </form>



    <%
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            //BaseDao.closeAll(conn, ps, rs);
            try {
                if (rs != null) {
                    rs.close();
                }
            } finally {
                try {
                    if (ps != null) {
                        ps.close();
                    }
                } finally {
                    if (conn != null) {
                        conn.close();
                    }
                }
            }
        }
    %>

</body>
<body>
    <%
        request.setCharacterEncoding("utf-8");
        String uuname = (String) session.getAttribute("uuname");
        String ctitle = request.getParameter("ctitle");
        String ccontent = request.getParameter("ccontent");
        //获取邮件列表页面输入的标题
        String contitle = (String) session.getAttribute("newcontitle");
        Connection conn = null;
        PreparedStatement ps = null;
        ResultSet rs = null;
        try {
            Class.forName("com.mysql.jdbc.Driver");
            //加载驱动
            String url = "jdbc:mysql://localhost:3306/mydb";
            String user = "root";
            String password = "root";
            conn = DriverManager.getConnection(url, user, password);
            // 连接对象
            //conn = BaseDao.getConnection();
    %>
    <%
        Msg msg = new Msg();
            ps = conn.prepareStatement("select * from msg where title=?and username=?");
            ps.setString(1, contitle);
            ps.setString(2, uuname);
            rs = ps.executeQuery();
            while (rs.next()) {
            ps = conn.prepareStatement("insert into msg(username,title,msgcontent,sendto,state,msg_create_date)" + "values('"
                    + rs.getString("sendto") + "','" + ctitle + "','" + ccontent + "','"
                    + uuname + "','" + "1" + "','"+"2020-04-27"+"')");
                    ps.executeUpdate();
                    request.getRequestDispatcher("index.jsp").forward(request, response);
    %>
    <%
        }
    %>
    <%
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            //BaseDao.closeAll(conn, ps, rs);
            try {
                if (rs != null) {
                    rs.close();
                }
            } finally {
                try {
                    if (ps != null) {
                        ps.close();
                    }
                } finally {
                    if (conn != null) {
                        conn.close();
                    }
                }
            }
        }
    %>




    <br>
</body>
<body>
    <%
        request.setCharacterEncoding("utf-8");
        String uuname = (String) session.getAttribute("uuname");
        //获取邮件列表页面输入的标题
        //从content.jsp session传过来的
        String contitle = (String) session.getAttribute("newcontitle");
        Connection conn = null;
        PreparedStatement ps = null;
        ResultSet rs = null;
        try {
            Class.forName("com.mysql.jdbc.Driver");
            //加载驱动
            String url = "jdbc:mysql://localhost:3306/mydb";
            String user = "root";
            String password = "root";
            conn = DriverManager.getConnection(url, user, password);
            // 连接对象
            //conn = BaseDao.getConnection();
    %>
    <table align="center">
        <tr>
            <td>username &nbsp;&nbsp;&nbsp;</td>
            <td>title&nbsp;&nbsp;&nbsp;</td>
            <td>msgcontent&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
            <td>state&nbsp;&nbsp;&nbsp;</td>
            <td>sendto&nbsp;&nbsp;&nbsp;</td>
            <td>msg_create_date</td>
        </tr>
        <%
            Msg msg = new Msg();
                ps = conn.prepareStatement("delete from msg where title=?and username=?");
                // 执行sql语句
                ps.setString(1, contitle);
                ps.setString(2, uuname);
                ps.executeUpdate();
                ps = conn.prepareStatement("select * from msg where username=?");
                ps.setString(1, uuname);
                rs = ps.executeQuery();
                while (rs.next()) {
        %>
        <tr>
            <td><%=rs.getString("username")%></td>
            <td><%=rs.getString("title")%></td>
            <td><%=rs.getString("msgcontent")%></td>

            <td>
                <%
                    if (rs.getString("state").equals("1")) {
                %> <%
     out.print("未读");
 %> <%
     } else {
 %> <%
     out.print("已读");
 %> <%
     }
 %>
            </td>
            <td><%=rs.getString("sendto")%></td>
            <td><%=rs.getString("msg_create_date")%></td>
        </tr>
        <%
            }
        %>
    </table>
    <%
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            //BaseDao.closeAll(conn, ps, rs);
            try {
                if (rs != null) {
                    rs.close();
                }
            } finally {
                try {
                    if (ps != null) {
                        ps.close();
                    }
                } finally {
                    if (conn != null) {
                        conn.close();
                    }
                }
            }
        }
    %>
    <br>
</body>
<body>
    <%
        request.setCharacterEncoding("utf-8");
        String uuname = (String) session.getAttribute("uuname");
        //获取邮件列表页面输入的标题
        //从content.jsp session传过来的
        String contitle = (String) session.getAttribute("newcontitle");
        Connection conn = null;
        PreparedStatement ps = null;
        ResultSet rs = null;
        try {
            Class.forName("com.mysql.jdbc.Driver");
            //加载驱动
            String url = "jdbc:mysql://localhost:3306/mydb";
            String user = "root";
            String password = "root";
            conn = DriverManager.getConnection(url, user, password);
            // 连接对象
            //conn = BaseDao.getConnection();
    %>
    <table align="center">
        <tr>
            <td>username &nbsp;&nbsp;&nbsp;</td>
            <td>title&nbsp;&nbsp;&nbsp;</td>
            <td>msgcontent&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
            <td>state&nbsp;&nbsp;&nbsp;</td>
            <td>sendto&nbsp;&nbsp;&nbsp;</td>
            <td>msg_create_date</td>
        </tr>
        <%
            Msg msg = new Msg();
                ps = conn.prepareStatement("delete from msg where title=?and username=?");
                // 执行sql语句
                ps.setString(1, contitle);
                ps.setString(2, uuname);
                ps.executeUpdate();
                ps = conn.prepareStatement("select * from msg where username=?");
                ps.setString(1, uuname);
                rs = ps.executeQuery();
                while (rs.next()) {
        %>
        <tr>
            <td><%=rs.getString("username")%></td>
            <td><%=rs.getString("title")%></td>
            <td><%=rs.getString("msgcontent")%></td>

            <td>
                <%
                    if (rs.getString("state").equals("1")) {
                %> <%
     out.print("未读");
 %> <%
     } else {
 %> <%
     out.print("已读");
 %> <%
     }
 %>
            </td>
            <td><%=rs.getString("sendto")%></td>
            <td><%=rs.getString("msg_create_date")%></td>
        </tr>
        <%
            }
        %>
    </table>
    <%
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            //BaseDao.closeAll(conn, ps, rs);
            try {
                if (rs != null) {
                    rs.close();
                }
            } finally {
                try {
                    if (ps != null) {
                        ps.close();
                    }
                } finally {
                    if (conn != null) {
                        conn.close();
                    }
                }
            }
        }
    %>
    <br>
</body>

 

posted @ 2020-05-12 19:45  Zzqqf  阅读(103)  评论(0编辑  收藏  举报