zoukankan      html  css  js  c++  java
  • JSP第八次作业

    <body>
       <form action="dologin.jsp" method="post">
    用户名:<input type="text" name="uname" value="kitty" /><Br>
    密码 :<input type="password" name="upwd" value="777"/><br>
    
    <input type="submit" value="登录">
    
    </form>
      </body>
    <body>
        <%
            request.setCharacterEncoding("utf-8");
            String uname = (String) session.getAttribute("uname");
            String ctitle = request.getParameter("ctitle");
            String ccontent = request.getParameter("ccontent");
            String sendtoid = request.getParameter("sendtoid");
    
            String contitle = (String) session.getAttribute("newcontitle");
            session.setAttribute("uname", uname);
            Connection conn = null;
            PreparedStatement ps = null;
            ResultSet rs = null;
            try {
                Class.forName("com.mysql.jdbc.Driver");
                //加载驱动
                String url = "jdbc:mysql://localhost:3306/users";
                String user = "root";
                String password = "admin";
                conn = DriverManager.getConnection(url, user, password);
                // 连接对象
                //conn = BaseDao.getConnection();
        %>
        <%
        if(contitle!=null){
            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()) {
                ps = conn.prepareStatement("insert into msg(username,title,msgcontent,sendto,state,msg_create_date)" + "values('"
                        + rs.getString("sendto") + "','" + ctitle + "','" + ccontent + "','"
                        + uname + "','" + "1" + "','"+"2020-05-11"+"')");
                        ps.executeUpdate();
                        request.getRequestDispatcher("index.jsp").forward(request, response);
        %>
        <%
            }
            }else{
            Msg msg = new Msg();
                
            
                ps = conn.prepareStatement("insert into msg(username,title,msgcontent,sendto,state,msg_create_date)" + "values('"
                        + sendtoid + "','" + ctitle + "','" + ccontent + "','"
                        + uname + "','" + "1" + "','"+"2020-05-11"+"')");
                        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 uname = (String) session.getAttribute("uname");
            session.setAttribute("uname", uname);
            Connection conn = null;
            PreparedStatement ps = null;
            ResultSet rs = null;
            try {
                Class.forName("com.mysql.jdbc.Driver");
                //加载驱动
                String url = "jdbc:mysql://localhost:3306/users";
                String user = "root";
                String password = "admin";
                conn = DriverManager.getConnection(url, user, password);
                // 连接对象
                //conn = BaseDao.getConnection();
        %>
        
        <form action="insert.jsp" name="huifu" method="post">
            sendto :<input type="text" name="sendtoid"><br> <br> 
            
            标题:<input type="text" name="ctitle"><br> <br> 
            
            正文:<input type="text" name="ccontent"><br>
            <br>
            <input type="submit" value="发送">
            <a href="main.jsp">返回</a>
        </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 = request.getParameter("uname");
            session.setAttribute("uname", uname);
            Connection conn = null;
            PreparedStatement ps = null;
            ResultSet rs = null;
            try {
                Class.forName("com.mysql.jdbc.Driver");
                //加载驱动
                String url = "jdbc:mysql://localhost:3306/users";
                String user = "root";
                String password = "admin";
                conn = DriverManager.getConnection(url, user, password);
                // 连接对象
                //conn = BaseDao.getConnection();
        %>
        <a href="editemail.jsp">写邮件</a>
        <table align="center">
            <tr>
                <td>username</td>
                <td>title</td>
                <td>msgcontent</td>
                <td>state</td>
                <td>sendto</td>
                <td>msg_create_date</td>
            </tr>
            <%
                Msg msg = new Msg();
                    ps = conn.prepareStatement("select * from msg where username=?");
                    ps.setString(1, uname);
                    rs = ps.executeQuery();
                    while (rs.next()) {
            %>
            <tr>
                <td><%=rs.getString("username")%></td>
                <td><a href="content.jsp?id=<%=rs.getInt("msgid")%>"><%=rs.getString("title")%></a></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>
       
        <br>
    
        <%
            } 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>

  • 相关阅读:
    Android进程的优先级说明
    Android的有序广播和无序广播(解决安卓8.0版本之后有序广播的接收问题)
    Android开发中常用Dialog(普通弹窗&时间选择器&日历选择器)
    Android的显示意图和隐式意图总结
    Android的启动模式
    怎么评论一段php语言文本单词one-hot编码的健壮性
    python 基础知识,解决模板引擎实现原理流程
    SQL----EXISTS 关键字EXISTS基本意思
    omcat启动Publishing failed with multiple errors
    AngularJs directive详解及示例代码
  • 原文地址:https://www.cnblogs.com/shenxiaoqi/p/12879062.html
Copyright © 2011-2022 走看看