JSP第十二周练习

1.实现 删除 回复邮件

 1 <%@page import="com.wl.email.domain.User"%>
 2 <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
 3 <%@page import="com.wl.email.domain.Email"%>
 4 <%@page import="com.wl.email.service.EmailService"%>
 5 <%@page import="com.wl.email.dao.impl.IEmailDAOImpl" %>
 6 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
 7 <html>
 8   <head>
 9     <title>My JSP 'AllService.jsp' starting page</title>
10 
11   </head>
12   
13   <body>
14           <%
15               IEmailDAOImpl ieDAO = new IEmailDAOImpl();
16               EmailService ese = new EmailService();
17               String cmd = request.getParameter("cmd");
18               
19               int cc = 0;
20               if(cmd.equals("delete")){
21                   cc = 3;
22               }else if(cmd.equals("sender")){
23                   cc = 32;
24               }
25               switch(cc){
26                   case 3:
27                       String id = request.getParameter("id");
28                       ese.delById(Long.parseLong(id));
29                       break;
30                   case 32:
31                       String sender = request.getSession().getAttribute("USER_IN_SESSION").toString();
32                       // String sender = user.getUsername();
33                       String address = request.getParameter("address");
34                       String tittle = request.getParameter("tittle");
35                       String content = request.getParameter("content");
36                       String sendDate = new Date().toString();
37                       Email email = new Email(new Long(99),address,sender,tittle,content,sendDate,0);
38                       //Email email = new Email(new Long(99),"1","2","2","4","5",0);
39                       ieDAO.add(email);
40                       break;
41                       
42               }
43               //response.setHeader("refresh", "0;Home.jsp");
44             //response.sendRedirect("Home.jsp");  
45             request.getRequestDispatcher("Home.jsp").forward(request, response);            
46           
47            %>
48   
49   
50   
51   </body>
52 </html>
AllService

 

 

 

 

 


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

 1     @Override
 2     public void update(Long id) {
 3         Connection conn = null;
 4         PreparedStatement ps = null;
 5         try {
 6             conn = JDBCUtils.getConn();
 7             String sql = "UPDATE email SET state = 1 WHERE id=?";
 8             ps = (PreparedStatement) conn.prepareStatement(sql);
 9             ps.setLong(1, id);
10             int row = ps.executeUpdate();
11             System.out.println((row > 0)?(id+"已读成功"):(id+"已读失败"));
12         } catch (SQLException e) {
13             e.printStackTrace();
14         }finally{
15             JDBCUtils.closeAll(conn, ps, null);
16         }
17         
18     }
update

 

posted @ 2022-05-22 20:01  L'童话故事  阅读(22)  评论(0编辑  收藏  举报