jsp9

<%--
  Created by IntelliJ IDEA.
  User: xinfeng
  Date: 2020/5/8
  Time: 15:58
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>$Title$</title>
</head>
<body>
<form action="dologin.jsp" method="post">
    用户名:<input type="text" name="uname" /><Br>
    密码 :<input type="password" name="upwd" /><br>

    <input type="submit" value="登录">

</form>
</body>
</html>
jsp9
jsp9
<%--
  Created by IntelliJ IDEA.
  User: xinfeng
  Date: 2020/5/8
  Time: 15:59
  To change this template use File | Settings | File Templates.
--%>
<%@page import="com.gd.dao.UsersDao" %>
<%@page import="com.gd.entity.Users" %>
<%@ page import="javax.swing.*" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    request.setCharacterEncoding("utf-8");
    String uname = request.getParameter("uname");
    String upwd = request.getParameter("upwd");
    UsersDao ud = new UsersDao();
    if (uname.equals("")) {
        //用户名为空的情况
        String msg = "用户名不能为空!";
        int type = JOptionPane.YES_NO_OPTION;
        String title = "信息提示";
        JOptionPane.showMessageDialog(null, msg, title, type);
        request.getRequestDispatcher("index.jsp").forward(request, response);
    } else {
        //密码账号登录成功
        if (ud.login(uname, upwd)) {
            Users u = new Users();
            u.setUsername(uname);
            u.setPassword(upwd);
            session.setAttribute("user", u);
            request.getRequestDispatcher("main.jsp").forward(request, response);
        } else {
            //账号密码不匹配
            String msg = "用户名或密码不正确,登录失败!";
            int type = JOptionPane.YES_NO_OPTION;
            String title = "信息提示";
            JOptionPane.showMessageDialog(null, msg, title, type);
            request.getRequestDispatcher("index.jsp").forward(request, response);
        }

    }
%>
jsp9
jsp9
<%--
  Created by IntelliJ IDEA.
  User: xinfeng
  Date: 2020/5/8
  Time: 16:14
  To change this template use File | Settings | File Templates.
--%>
<%@ page import="com.gd.dao.MsgDao" %>
<%@ page import="com.gd.entity.Msg" %>
<%@ page import="com.gd.entity.Users" %>
<%@ page import="java.util.List" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
<div align="center" style="font-size: 45px">欢迎登录<%
    Users u = (Users) session.getAttribute("user");
    out.print(u.getUsername());
    MsgDao md = new MsgDao();
    List<Msg> list = md.getMailByReceiver(u.getUsername());
%></div>
<table border="1" width="60%" align="center" style="margin-top: 150px">
    <tr>
        <td>发件人</td>
        <td>标题</td>
        <td>收件人</td>
        <td>状态</td>
        <td>时间</td>
        <td>&nbsp;</td>
    </tr>

    <%
        for (int i = 0; i < list.size(); i++) {
    %>
    <tr>
        <td><%=list.get(i).getUsernname() %>
        </td>
        <td>
            <a href="detail.jsp?id=<%=list.get(i).getMsgid()%>&&username=<%=list.get(i).getUsernname()%>"><%=list.get(i).getTitle()%>
            </a></td>
        <td><%=list.get(i).getSendto() %>
        </td>
        <td><% if (list.get(i).getState() == 1) { %>
            <img src="images/sms_unReaded.png"/>
            <%} else { %>
            <img src="images/sms_readed.png"/>
            <%} %>


        </td><!-- 0已读,1未读 -->
        <td><%=list.get(i).getMsg_create_date() %>
        </td>
        <td><a href="delete.jsp?id=<%=list.get(i).getMsgid()%>">删除</a></td>

    </tr>
    <%} %>
</table>
<br>
<br>
<div align="center"><a href="sendMessage.jsp">发送信息请单击此处</a></div>
</body>
</html>
jsp9
jsp9
<%@ page import="com.gd.dao.MsgDao" %>
<%@ page import="com.gd.entity.Msg" %><%--
  Created by IntelliJ IDEA.
  User: xinfeng
  Date: 2020/5/8
  Time: 16:15
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
<%
    int id = Integer.parseInt(request.getParameter("id"));
    String username=request.getParameter("username");
    session.setAttribute("username",username);
    MsgDao md = new MsgDao();
    Msg m = md.getMailById(id);
%>
<p>
    题目:<%=m.getTitle()%>
</p>
<p>
    来自:<%=m.getUsernname()%>
</p>
<p>
    时间:<%=m.getMsg_create_date()%>
</p>
<p>
    内容:<%=m.getMsgcontent()%>
</p>
<a href="reply.jsp">回复</a>
<a href="main.jsp">返回</a>
</body>
</html>
jsp9
jsp9
<%--
  Created by IntelliJ IDEA.
  User: xinfeng
  Date: 2020/5/8
  Time: 22:49
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
<form action="doreply.jsp" method="post">
    <p>
        题&nbsp;&nbsp;&nbsp;目:<input type="text" name="title1">
    </p>
    <p>
        内&nbsp;&nbsp;&nbsp;容:<input type="text" name="content">
    </p>
    <input type="submit" value="提交">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <a href="main.jsp">返回</a>

</form>
</body>
</html>
jsp9
jsp9
<%@ page import="com.gd.dao.ReplyDao" %>
<%@ page import="com.gd.entity.Users" %>
<%@ page import="java.sql.PreparedStatement" %>
<%@ page import="java.util.Date" %>
<%@ page import="javax.swing.*" %>
<%--
  Created by IntelliJ IDEA.
  User: xinfeng
  Date: 2020/5/8
  Time: 23:11
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    request.setCharacterEncoding("utf-8");
    String title1 = request.getParameter("title1");
    String content = request.getParameter("content");
    String uname = (String) session.getAttribute("username");
    Users u = (Users) session.getAttribute("user");
    String sendto = u.getUsername();
    ReplyDao Dao = new ReplyDao();
    Date utilDate = new Date();
    java.sql.Date sqlDate = new java.sql.Date(utilDate.getTime());
    if (title1.equals("") || content.equals("")) {
        //标题和内容为空的情况
        String msg = "标题或内容为空!";
        int type = JOptionPane.YES_NO_OPTION;
        String title = "信息提示";
        JOptionPane.showMessageDialog(null, msg, title, type);
        request.getRequestDispatcher("reply.jsp").forward(request, response);
    } else {
        if (Dao.insert(uname, title1, content, sendto, 1, sqlDate)) {
            request.getRequestDispatcher("reply.jsp").forward(request, response);
        }


    }

%>
jsp9
jsp9
<%--
  Created by IntelliJ IDEA.
  User: xinfeng
  Date: 2020/5/9
  Time: 14:56
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
<form action="dosendMessage.jsp" method="post">
    <p>
        接收人:<input type="text" name="name">
    </p>
    <p>
        题&nbsp;&nbsp;&nbsp;目:<input type="text" name="title">
    </p>
    <p>
        内&nbsp;&nbsp;&nbsp;容:<input type="text" name="content">
    </p>
    <input type="submit" value="提交">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <a href="main.jsp">返回</a>

</form>
</body>
</html>
jsp9
jsp9
<%--
  Created by IntelliJ IDEA.
  User: xinfeng
  Date: 2020/5/9
  Time: 14:56
  To change this template use File | Settings | File Templates.
--%>
<%@ page import="com.gd.dao.SendMsessage" %>
<%@ page import="com.gd.entity.Users" %>
<%@ page import="javax.swing.*" %>
<%@ page import="java.util.Date" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    request.setCharacterEncoding("utf-8");
    String title = request.getParameter("title");
    String name = request.getParameter("name");
    String content = request.getParameter("content");
    Users u = (Users) session.getAttribute("user");
    String sendto = u.getUsername();
    Date utilDate = new Date();
    SendMsessage SM = new SendMsessage();
    java.sql.Date sqlDate = new java.sql.Date(utilDate.getTime());
    if (SM.checkinsert(name)) {
        if (name.equals("") || title.equals("") || content.equals("")) {
            //标题和内容为空的情况
            String msg = "接收人或标题或内容为空!";
            int type = JOptionPane.YES_NO_OPTION;
            String title1 = "信息提示";
            JOptionPane.showMessageDialog(null, msg, title1, type);
            request.getRequestDispatcher("sendMessage.jsp").forward(request, response);
        } else {
            if (SM.insert(sendto, title, content, name, 1, sqlDate)) {
                request.getRequestDispatcher("main.jsp").forward(request, response);
            }
        }
    } else {
        //没有该联系人
        String msg = "无该收件人!";
        int type = JOptionPane.YES_NO_OPTION;
        String title1 = "信息提示";
        JOptionPane.showMessageDialog(null, msg, title1, type);
        response.sendRedirect("sendMessage.jsp");
    }

%>
jsp9
jsp9
<%@ page import="com.gd.entity.Msg" %>
<%@ page import="com.gd.dao.MsgDao" %>
<%@ page import="javax.swing.*" %><%--
  Created by IntelliJ IDEA.
  User: xinfeng
  Date: 2020/5/9
  Time: 14:13
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    int id = Integer.parseInt(request.getParameter("id"));
    MsgDao msg = new MsgDao();
    if (msg.delete(id)) {
        String mess = "删除成功!";
        int type = JOptionPane.YES_NO_OPTION;
        String title = "信息提示";
        JOptionPane.showMessageDialog(null, mess, title, type);
        response.sendRedirect("main.jsp");
    }

%>
jsp9
jsp9
package com.gd.dao;

import java.sql.*;

public class BaseDao {


    //获取连接
    public Connection getConnection() {
        Connection conn = null;
        try {
            Class.forName("com.mysql.jdbc.Driver");
            // 2.建立连接
            conn = DriverManager.getConnection(
                    "jdbc:mysql://localhost:3306/jdbc", "root", "1111");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return conn;
    }


    //关闭连接
    protected void closeAll(Connection con, PreparedStatement ps, ResultSet rs) {
        try {
            if (rs != null)
                rs.close();
            if (ps != null)
                ps.close();
            if (con != null)
                con.close();

        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

}
jsp9
jsp9
package com.gd.dao;

import com.gd.entity.Msg;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class MsgDao extends BaseDao {
    Connection con = null;
    ResultSet rs = null;
    PreparedStatement ps = null;

    public List<Msg> getMailByReceiver(String receiverName) {
        List<Msg> list = new ArrayList<Msg>();

        try {
            con = getConnection();
            String sql = "select * from msg where sendto=?";
            ps = con.prepareStatement(sql);
            ps.setString(1, receiverName);
            rs = ps.executeQuery();

            while (rs.next()) {
                Msg msg = new Msg();
                msg.setMsgid(rs.getInt("msgid"));
                msg.setMsgcontent(rs.getString("msgcontent"));
                msg.setMsg_create_date(rs.getDate("msg_create_date"));
                msg.setSendto(rs.getString("sendto"));
                msg.setState(rs.getInt("state"));
                msg.setTitle(rs.getString("title"));
                msg.setUsernname(rs.getString("username"));
                list.add(msg);
            }
            closeAll(con, ps, rs);

        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        return list;
    }

    public Msg getMailById(int id) {
        Msg msg = new Msg();
        try {
            con = getConnection();
            String sql = "select * from msg where msgid=?";
            ps = con.prepareStatement(sql);
            ps.setInt(1, id);
            rs = ps.executeQuery();
            while (rs.next()) {
                msg.setMsgid(rs.getInt("msgid"));
                msg.setMsgcontent(rs.getString("msgcontent"));
                msg.setMsg_create_date(rs.getDate("msg_create_date"));
                msg.setSendto(rs.getString("sendto"));
                msg.setState(rs.getInt("state"));
                msg.setTitle(rs.getString("title"));
                msg.setUsernname(rs.getString("username"));

            }
            closeAll(con, ps, rs);

        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return msg;
    }

    public boolean delete(int id) {
        try {
            con = getConnection();
            String sql = "delete from msg where msgid=?";
            ps = con.prepareStatement(sql);
            ps.setInt(1, id);
            int row = ps.executeUpdate();
            if (row > 0) {
                return true;
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            closeAll(con, ps, null);
        }
        return false;
    }


}
jsp9
jsp9
package com.gd.dao;

import java.sql.Connection;
import java.sql.Date;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class ReplyDao extends BaseDao {
    Connection conn = null;
    PreparedStatement ps = null;

    public boolean insert(String username, String title, String msgcontent, String sendto, int state, Date msg_create_date) throws SQLException {

        conn = getConnection();
        String sql = "insert into msg(username,title,msgcontent,sendto,state,msg_create_date) values (?,?,?,?,?,?)";
        ps = conn.prepareStatement(sql);

        ps.setString(1, sendto);
        ps.setString(2, title);
        ps.setString(3, msgcontent);
        ps.setString(4, username);
        ps.setInt(5, state);
        ps.setDate(6, msg_create_date);
        int row = ps.executeUpdate();
        if (row > 0) {
            closeAll(conn, ps, null);
            return true;
        } else {
            closeAll(conn, ps, null);
            return false;
        }


    }

}
jsp9
jsp9
package com.gd.dao;

import java.sql.*;

public class SendMsessage extends BaseDao {
    Connection conn = null;
    PreparedStatement ps = null;
    ResultSet rs = null;

    public boolean checkinsert(String name) throws SQLException {
        conn = getConnection();
        String sql2 = "select * from users where username=?";
        ps = conn.prepareStatement(sql2);
        ps.setString(1, name);
        rs = ps.executeQuery();
        if (rs.next()) {
            closeAll(conn, ps, rs);
            return true;
        } else {
            closeAll(conn, ps, rs);
            return false;
        }
    }

    public boolean insert(String username, String title, String msgcontent, String sendto, int state, Date msg_create_date) throws SQLException {

        conn = getConnection();
        String sql = "insert into msg(username,title,msgcontent,sendto,state,msg_create_date) values (?,?,?,?,?,?)";
        ps = conn.prepareStatement(sql);

        ps.setString(1, username);
        ps.setString(2, title);
        ps.setString(3, msgcontent);
        ps.setString(4, sendto);
        ps.setInt(5, state);
        ps.setDate(6, msg_create_date);
        int row = ps.executeUpdate();
        if (row > 0) {
            closeAll(conn, ps, null);
            return true;
        } else {
            closeAll(conn, ps, null);
            return false;
        }


    }
}
jsp9
jsp9
package com.gd.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class UsersDao extends BaseDao {
    public boolean login(String uname, String upwd) throws SQLException {
        Connection conn = getConnection();
        String sql = "select * from users where username=? and password=?";
        PreparedStatement ps = conn.prepareStatement(sql);
        ps.setString(1, uname);
        ps.setString(2, upwd);
        ResultSet rs = ps.executeQuery();
        if (rs.next()) {
            closeAll(conn, ps, rs);
            return true;
        } else {
            closeAll(conn, ps, rs);
            return false;

        }
    }

}
jsp9
jsp9
package com.gd.entity;

import java.util.Date;

public class Msg {
    int msgid;
    String usernname;
    String title;
    String msgcontent;
    int state;
    String sendto;
    Date msg_create_date;

    public int getMsgid() {
        return msgid;
    }

    public void setMsgid(int msgid) {
        this.msgid = msgid;
    }

    public String getUsernname() {
        return usernname;
    }

    public void setUsernname(String usernname) {
        this.usernname = usernname;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getMsgcontent() {
        return msgcontent;
    }

    public void setMsgcontent(String msgcontent) {
        this.msgcontent = msgcontent;
    }

    public int getState() {
        return state;
    }

    public void setState(int state) {
        this.state = state;
    }

    public String getSendto() {
        return sendto;
    }

    public void setSendto(String sendto) {
        this.sendto = sendto;
    }

    public Date getMsg_create_date() {
        return msg_create_date;
    }

    public void setMsg_create_date(Date msg_create_date) {
        this.msg_create_date = msg_create_date;
    }
}
jsp9
jsp9
package com.gd.entity;

public class Users {
    String username;
    String password;
    String email;

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }


}

jsp9

上一篇:html特效


下一篇:js打印页面添加分页