public boolean addMail(Msg msg){
Statement st =null;
Connection con=null;
try{
//获取连接
con = getConnection();
//书写SQL语句
st = con.createStatement();
java.util.Date msg_crate_date = msg.getMsg_create_date();
String sqlmsg_create_date = String.format("%tF", msg_crate_date);
String sql = "insert into msg(username,title,msgcontent,state,sendto,msg_create_date) "+"values('"+msg.getUsernname()+"','"
+msg.getTitle()+"','"
+msg.getMsgcontent()+"','"
+msg.getState()+"','"
+msg.getSendto()+"','"
+sqlmsg_create_date+"'"
+")";
int row = st.executeUpdate(sql);
if(row>0){
//发送成功
return true;
}
}catch(SQLException e){
e.printStackTrace();
}finally{
closeAll(con, st, null);
}
return false;
}
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <base href="<%=basePath%>"> <title>My JSP 'write.jsp' starting page</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> <!-- <link rel="stylesheet" type="text/css" href="styles.css"> --> </head> <body> <form action="" method="post"> 发件人:<input type="text" name="sjr" value="ls" readonly="readonly"/><br/> 标 题:<input type="text" name="bt" /> <br/> 正 文:<br/> <textarea rows="10" cols="30" name="zw"></textarea> <br/> <input type="submit" value="发送" /> <a href="main.jsp">返回</a> </form> </body> </html>




浙公网安备 33010602011771号