第十一周jsp作业

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

2.建model层
entity,dao包

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

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>My JSP 'denglu.jsp' starting page</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()">
    </form>
    <hr>
    <a href="reg.jsp">返回注册</a>
</body>
</html>
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ page import="com.gd.dao.UserDao"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>My JSP 'dologin.jsp' starting page</title>

</head>

<body>
    <%
        request.setCharacterEncoding("utf-8");
        String uname = request.getParameter("uname");
        String upwd = request.getParameter("upwd");
        UserDao ud = new UserDao();
        if (ud.login(uname, upwd)) {
            session.setAttribute("uname",uname);
            request.getRequestDispatcher("main.jsp").forward(
                    request,response);
        } else {
            out.print("登录失败,即将跳回登录页......");
            response.setHeader("refresh", "3;url=denglu.jsp");
        }
    %>
</body>
</html>
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ page import="com.gd.dao.UserDao"%>
<%@ page import="com.gd.dao.MsgDao"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>My JSP 'doreg.jsp' starting page</title>

</head>

<body>

    <%
        request.setCharacterEncoding("utf-8");
        String uname = request.getParameter("uname");
        String upwd = request.getParameter("upwd");

        UserDao ud = new UserDao();
        MsgDao md = new MsgDao();
        if (ud.register(uname, upwd) > 0) {
            session.setAttribute("uname", uname);
            request.getRequestDispatcher("denglu.jsp").forward(request,
                    response);
        } else {
            out.print("注册失败,请重新注册.......");
            response.setHeader("refresh", "3;url=reg.jsp");
        }
    %>
</body>
</html>
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ page import="com.gd.entity.Msg"%>
<%@ page import="com.gd.dao.MsgDao"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>My JSP 'main.jsp' starting page</title>

</head>

<body >
    <%
        String uname = (String) session.getAttribute("uname");
    %>
    欢迎你<%
        out.print(uname);
    %>使用邮箱
    <hr>
    <table border="2px solid black">
        <tr>
            <td>id</td>
            <td>发件人</td>
            <td>标题</td>
            <td>内容</td>
            <td>已读未读状态</td>
            <td>收件人</td>
            <td>发送时间</td>
        </tr>
        <%
            MsgDao md = new MsgDao();
            List<Msg> list=md.getMailByReceiver(uname);
            for (Msg m : list) {
        %>
        <tr>
            <td><%=m.getMsgid()%></td>
            <td><%=m.getUsername()%></td>
            <td><%=m.getTitle()%></td>
            <td><%=m.getMsgcontent()%></td>
            <td>
                <%
                    int state = Integer.parseInt(m.getState()); 
                        if (state == 1) {
                %> <img src="image/yidu.png"> <%
     ;
         } else {
 %> <img src="image/weidu.png"> <%
     ;
         }
 %>
            </td>
            <td><%=m.getSendto()%></td>
            <td><%=m.getSetMsg_create_date()%></td>
        </tr>
        <%
            }
        %>
    </table>
</body>
</html>
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>My JSP 'reg.jsp' starting page</title>
    
  </head>
  
  <body bgcolor=#ffccff>
  <script type="text/javascript">
        function validate() {
            if (registerForm.uname.value == "") {
                alert("账号不能为空!");
                return;
            }
            if (registerForm.upwd.value == "") {
                alert("密码不能为空!");
                return;
            }
            registerForm.submit();
        }
    </script>

    <form name="registerForm" action="doreg.jsp" method="post">
        用户名:<input type="text" name="uname"><br> 
        密   码: <input type="password" name="upwd"><br> 
        <input type="submit" value="注册"><hr>
    </form><hr>
    <a href="denglu.jsp">返回登录</a>
</body>
</html>

 

 

 

 

 

posted @ 2022-05-14 13:59  张秋菊  阅读(34)  评论(0编辑  收藏  举报