第十二周作业

添加查询改变内容是否已经阅读功能

    @Override
    public void updatemesById(Integer updateid) {
        // 通过id更新数据
        try {
            String sql = "UPDATE  t_email SET model='已读' where id=?";
            conn = utils.getConnection();
            ps = conn.prepareStatement(sql);
            ps.setInt(1, updateid);
            ps.executeUpdate();
        }catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }finally {
            try {
                utils.Close(conn, ps, rs);
            } catch (SQLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
        <%@ taglib uri="http://java.sun.com/jsp/jstl/core"  prefix= "c"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>我的邮箱</title>
</head>
<body>
 <%@ include file="/C.jsp"%>
<div align="center"><h4>--->增加信件<---</h4>
<form action="${pageContext.request.contextPath}/myemail" method = "post">
 <table>
 <tr>
 <td>
 寄件人:
 <input type = "text" name = "sendname">
 </td>
 </tr>
 <tr>
 <td>
 收件人:
 <input type = "text" name = "receivename">
 </td>
 </tr>
 <tr>
 <td>
 内&nbsp&nbsp&nbsp容:
 <input type = "text" name = "emailcontent">
 </td>
 </tr>
 <tr>
 <td>
 已&nbsp&nbsp&nbsp读:
 <input type = "text" name = "model">
 </td>
 </tr>
  <tr>
 <td>
 日&nbsp&nbsp&nbsp期:
 <input type = "text" name = "email">
 </td>
 </tr>
 <tr>
 <td>
 <input type = "submit" value="录入" >
 </td>
 </tr>
</table>
</form>
</div>
<br>
<div align="center"><b1 >-------------------------------------------------------------------</b1></div>
<br>
<div align="center"><h4>--->查询信件<---</h4>
<h4>--->"2"代表没有查阅,"1"代表已经查阅<---</h4>
<div align="center" id = "mydiv">登录信息通知处==</div>
	  <table border="1">
	            <th>Id</th>
				<th>寄件人 </th>
				<th>收件人 </th>
				<th>邮寄内容</th> 
				<th>是否查阅</th>
				<th>日期</th>
				<c:forEach items = "${emails}" var = "em" >
				<tr>
				<td>
				${em.id}
				</td>
				<td>
				${em.sendname}
				</td>
				<td>
				${em.receivename}
				</td>
				<td>
				${em.emailcontent}
				</td>
				<td>
				${em.model}
				</td>
				<td>
				${em.email}
				</td>
				<td>
			    
                <input type="button" value="删除"   id = "${em.id}" onclick="dodelete(id)" />
                  <input type="button" value="查阅"   id = "${em.id}" onclick="doupdate(id)" />

				</tr>

				</c:forEach>
			  </table>
			 <form action = "${pageContext.request.contextPath}/selectemail" method = "post">
              <input type = "submit" value = "查询信件"/>
              </form>
</div>

<script type="text/javascript">
function dodelete(id){
 
      var xhr = new XMLHttpRequest();
	  //请求连接(绑定事件)
	  xhr.onreadystatechange=function(){
		  if(xhr.readyState==4){
			  var json = xhr.responseText;
			  eval("var jsonS="+json);//json = "jsonStr"
			  if(jsonS.success){
				  document.getElementById("mydiv").innerHTML="删除成功"; 
				
			  }else{
				 document.getElementById("mydiv").innerHTML="删除失败"; 
			  }
		  }
	  }
	  //请求处理(准备好需要验证的信息)
	  //获取参数

    //var Ajaxurl = "login?studentsum"+sum+"&studentpassword"+password;
	  xhr.open("POST","/EmailHomework/deleate",true);
	  //请求完成,且响应就绪
	  //如果是发送post请求必须加上以下代码:application/x-www-form-urlencoded为为了防止乱码出现
	  xhr.setRequestHeader("Content-type","application/x-www-form-urlencoded;charset=utf-8");
	  xhr.send("id="+id);
}
function doupdate(id){
	 
    var xhr = new XMLHttpRequest();
	  xhr.onreadystatechange=function(){
		  if(xhr.readyState==4){
			  var json = xhr.responseText;
			  eval("var jsonS="+json);
			  if(jsonS.success){
				  document.getElementById("mydiv").innerHTML="修改成功"; 
				
			  }else{
				 document.getElementById("mydiv").innerHTML="修改失败"; 
			  }
		  }
	  }

	  xhr.open("POST","/EmailHomework/update",true);

	  xhr.setRequestHeader("Content-type","application/x-www-form-urlencoded;charset=utf-8");
	  xhr.send("id="+id);
}

  

posted @ 2022-05-18 13:12  李成前  阅读(24)  评论(0编辑  收藏  举报