第十二次作业

1.实现 删除 回复邮件
2.实现阅读邮件功能:在main.jsp中点击任意邮件的标题,进入到detail.jsp显示邮件详情,包括发件人,主题,内容,时间。同时需要把邮件状态修改为已读。

<%--delete.jsp--%>
<%@page import="com.dao.MsgDao"%>
<%@page import="com.entity.Msg"%>
<%@page import="com.dao.UsersDao"%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
<%
    request.setCharacterEncoding("utf-8");

    int id = Integer.parseInt(request.getParameter("id"));
    MsgDao md = new MsgDao();
    md.delMail(id);
    out.print("刪除成功......");
    response.setHeader("refresh", "2;url=main.jsp");
    //response.sendRedirect("main.jsp");
%>

</body>
</html>
<%--detail.jsp--%>
<%@ page import="com.entity.Msg"%>
<%@ page import="com.dao.MsgDao"%>
<%@ page import="com.dao.UsersDao"%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<%
    request.setCharacterEncoding("utf-8");
    String msgid = request.getParameter("id");
    int idd = Integer.parseInt(msgid);
    MsgDao md = new MsgDao();
    md.update(idd);
    Msg m =md.read(idd);
%>
<table>
    <tr>
        <td>发件人:</td>
        <td><input type="text" name="username" style="border: none"
                   value="<%=m.getUsername()%>">
        </td>
    </tr>
    <tr>
        <td>主题:</td>
        <td><input type="text" name="title" style="border: none"
                   value="<%=m.getTitle()%>">
        </td>
    </tr>
    <tr>
        <td>时间:</td>
        <td><input type="text" name="msg_create_date" style="border: none"
                   value="<%=m.getMsg_create_date()%>">
        </td>
    </tr>
    <tr>
        <td>收件人:</td>
        <td><input type="text" name="sendto" style="border: none"
                   value="<%=m.getSendto()%>">
        </td>
    </tr>
    <tr>
        <td>内容:</td>
        <td><div style="border: none;outline: none;overflow: inherit;">
            <%=m.getMsgcontent()%></div>
        </td>
    </tr>
</table>
<br>
<a href="main.jsp">返回</a>
</body>
</body>
</html>
<%--dologin.jsp--%>
<%@page import="com.dao.UsersDao"%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
<%
    String uname = request.getParameter("uname");
    String upwd =request.getParameter("upwd");
    UsersDao usersDao=new UsersDao();
    if(usersDao.login(uname, upwd)){
        session.setAttribute("uname", uname);
        request.getRequestDispatcher("main.jsp").forward(request, response);
    }
    else{
        out.print("登录失败,5s后跳转登录页面");
        response.setHeader("refresh", "5;url=login.jsp");
    }
%>
</body>
</html>
<%--doreg.jsp--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@page import="com.dao.MsgDao"%>
<%@page import="com.dao.UsersDao"%>
<html>
<head>
    <title>Title</title>
</head>
<body>
<%
    String uname = request.getParameter("uname");
    String upwd = request.getParameter("upwd");
    UsersDao usersDao = new UsersDao();
    int i=usersDao.reg(uname, upwd);
    if(i>0){
        out.print("注册成功,即将跳到登录页.....");
        response.setHeader("refresh", "2;url=login.jsp");
    }else{
        out.print("注册失败,即将跳回注册页.....");
        response.setHeader("refresh", "2;url=reg.jsp");
    }
%>

</body>
</html>
<%--dowrite.jsp--%>
<%@page import="com.dao.MsgDao"%>
<%@page import="com.entity.Msg"%>
<%@page import="com.dao.UsersDao"%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
<%
    request.setCharacterEncoding("utf-8");
    String uname = (String) session.getAttribute("uname");
    String sendto = request.getParameter("receiver");
    String title = request.getParameter("title");
    String content = request.getParameter("content");

    Msg m = new Msg();
    m.setMsgcontent(content);
    m.setUsername(uname);
    m.setSendto(sendto);
    m.setTitle(title);

    MsgDao md = new MsgDao();
    md.addMsg(m);

    out.print("发送成功.....");
    response.setHeader("refresh", "3;url=main.jsp");
%>

</body>
</html>
<%--login.jsp--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
<script type="text/javascript">
    function validate(){
        if(loginForm.uname.value==""){
            alert("账号不能为空!");
            return;
        }
        if(loginForm.upwd.value==""){
            alert("密码不能为空!");
            return;
        }
        loginForm.submit();
    }
</script>

<form name="loginForm" action="dologin.jsp" method="post">

    用户名:<input type="text" name="uname"><br>
    密码: <input  type="password" name="upwd">
    <br>
    <input type="button" value="登录" onClick="validate()">
    <a href="reg.jsp">注册</a>
</form>

</body>
</html>
<%@page import="com.entity.Msg"%>
<%@page import="com.dao.MsgDao"%>
<%@ page import="java.util.List" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
  <head>
    <title></title>
  </head>
  <body >
  <%
    String uname = (String) session.getAttribute("uname");
  %>

  <hr>
  <a href="write.jsp">写邮件</a>
  <table border="1">
    <tr>
      <td>发件人</td>
      <td>标题</td>
      <td>状态</td>
      <td>时间</td>
      <td>操作</td>
      <td>操作</td>

        <%
                MsgDao md = new MsgDao();
                List<Msg> list = md.getMailByReceiver(uname);
                for (int i = 0; i < list.size(); i++) {
            %>

    <tr>
      <td><%=list.get(i).getUsername()%></td>
      <td><a href="detail.jsp?id=<%=list.get(i).getMsgid()%>"><%=list.get(i).getMsgcontent() %></a>
      </td>
      <td>
        <%
          if (list.get(i).getState() == 1) {
        %> <img  src="image/已读消息.png"/>
        <%
        } else {
        %><img  src="image/未读.png"/> <%
        }
      %>
      </td>
      <td><%=list.get(i).getMsg_create_date()%></td>
      <td><a href="delete.jsp?id=<%=list.get(i).getMsgid()%>">删除</a>
      </td>
      <td><a href="write.jsp?reply=<%=list.get(i).getUsername()%>">回复</a>
      </td>


    </tr>


    <%
      }
    %>

  </table>


  </body>
</html>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
<script type="text/javascript">
    function validate(){
        if(resForm.uname.value==""){
            alert("账号不能为空!");
            return;
        }
        if(resForm.upwd.value==""){
            alert("密码不能为空!");
            return;
        }
        resForm.submit();
    }
</script>
<form name="resForm" action="doreg.jsp" method="post">
    <b>用户名</b>
    <input type="text" name="uname" />
    <br />
    <b>密码</b>
    <input type="text" name="upwd" />
    <br />
    <input type="button" value="注册" onClick="validate()">
    <a href="login.jsp">登录</a>
</form>
</body>
</html>
<%--write.jsp--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
<form action="dowrite.jsp" method="post">
    收件人:<input type="text" name="receiver"  value="<%=request.getParameter("reply")%>"><br>
    主题: <input  type="text" name="title" ><br>
    内容    <textarea rows="6" cols="20" name="content"></textarea>
    <br>
    <input type="submit" value="发送">
</form>
</body>
</html>

 

posted @ 2022-05-22 20:55  叶鑫宇  阅读(18)  评论(0编辑  收藏  举报