08邮件

public boolean insert(Msg m) {
     try {
        String uname = m.getUsernname();
        PreparedStatement ps = null;
        Connection conn = getConnection();//获取连接  
        String sql="insert into msg(username,title,msgcontent,sendto,state,msg_create_date)"+"values('"
                    + uname + "','" + m.getTitle() + "','" + m.getMsgcontent() + "','"
                    + m.getSendto() + "','" + "1" + "','"+"2020-05-08"+"')";
            ps = conn.prepareStatement(sql);
            ps.executeUpdate();
        //Statement stmt = conn.createStatement();
        //stmt.executeUpdate(sql);
        closeAll(conn, ps, null);
        return true;
    } catch (Exception e) {
        // TODO: handle exception
        
        
    }
         
         
    return false; 
         
        
   }
     
<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
    <%@page import="com.gd.entity.Users"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Insert title here</title>
</head>
<body>
<% Users u = (Users) session.getAttribute("user");%>
  <form action="dosend.jsp" method="post">
            <table>
                <tr>
                    <td colspan="2">发送邮件</td>
                </tr>
                <tr>
                    <td>发件人:</td>
                    <td><input type="text" name="cuname" value="<%=u.getUsername()%>"></td>
                    
                </tr>
                <tr>
                    <td>收件人:</td>
                    <td><input type="text" name="csendto" value="zs"></td>
                    
                </tr>
                <tr>
                    <td>标题:</td>
                    <td><input type="text" name="ctitle" value=""></td>
                </tr>
                <tr>
                    <td>内容:</td>
                    <td><textarea name="cmsgcontent" cols="30" rows="6" ></textarea></td>
                </tr>
                <tr>
                    <td colspan="2">
                        
                        <input type="submit" value="发送">
                         
                        <a href="main.jsp"><input type="button" value="返回"></a>
                    </td>
                </tr>
            </table>
        </form>
    
</body>
</html>
<%@page import="com.gd.dao.MsgDao"%>
<%@page import="com.gd.entity.Msg"%>
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
    request.setCharacterEncoding("utf-8");
    String csendto = request.getParameter("csendto");
    String ctitle = request.getParameter("ctitle");
    String cmsgcontent = request.getParameter("cmsgcontent");
    String cuname = request.getParameter("cuname");
    Msg m =new Msg();
    MsgDao md=new MsgDao();
    m.setSendto(csendto);
    m.setTitle(ctitle);
    m.setMsgcontent(cmsgcontent);
    m.setUsernname(cuname);
    md.insert(m);
    session.setAttribute("Msg", m);
    request.getRequestDispatcher("index.jsp").forward(request, response);
    
%>

posted @ 2020-05-08 20:03  1014040868a  阅读(124)  评论(0编辑  收藏  举报