📄 savedraftservlet.java
字号:
package com.lovo.controller;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import com.lovo.po.Mail;
import com.lovo.po.MailVo;
import com.lovo.service.IMailBo;
import com.lovo.service.IMailBoImpl;
import com.lovo.service.IUserBo;
import com.lovo.service.IUserBoImpl;
public class SaveDraftServlet extends HttpServlet
{
/** userBo接口,用于业务方法调用 */
private IUserBo userBo = new IUserBoImpl();
/** mailBo接口,用于业务方法调用 */
private IMailBo mailBo = new IMailBoImpl();
/**
* The doGet method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to get.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
/** 设置响应文件类型及字符集编码 */
response.setContentType("text/html; charset=utf-8");
/** 设置响应头,让浏览器不缓存信息 */
response.setHeader("Cache-control", "no-cache");
/** 获取现在是存新的草稿还是草稿的更新的指示信息 */
HttpSession session = request.getSession();
String flag = (String)session.getAttribute("isUpdate");
/** 获取草稿所属userId */
int userId = Integer.parseInt(request.getParameter("whoSended"));
/** 获取邮件主题 */
String mailTitle = request.getParameter("mailTitle");
if(mailTitle.equals("")){mailTitle = "(无主题)";}
/** 获取邮件内容 */
String mailContent = request.getParameter("mailContent");
/** 获取并处理收件人 */
String temp = request.getParameter("whoReceive");
String[] receives = temp.split(";");
int whoReceive = userId;
if(receives.length != 0)
{
int temp2 = userBo.isEmailNameExist(receives[0]);
if(temp2 != -1)whoReceive = temp2;
}
/** 创建一个待发信件 */
Mail mail = new Mail();
/** 设置待发信件状态码 */
mail.setMailStatus(Mail.DRAFT_MAIL);
/** 设置待发信件标题 */
mail.setMailTitle(mailTitle);
/** 设置待发信件内容 */
mail.setMailContent(mailContent);
/** 设置待发信件所属用户 */
mail.setUserId(userId);
/** 设置待发信件的发件人 */
mail.setWhoSended(userId);
/** 设置待发信件的收件人 */
mail.setWhoReceive(whoReceive);
/**
* 如果要草稿已经存在,那么flag为true,则对草稿进行更新。
* 否则存为新草稿。
*/
if(flag != null && flag.equals("true"))
{
/** 更新草稿 */
MailVo mailVo = (MailVo)session.getAttribute("currentMail");
mail.setMailId(mailVo.getMailId());
mailBo.updateMail(mail);
}
else
{
/** 保存新草稿 */
mailBo.sendMail(mail);
}
/** 获得输出流 */
PrintWriter writer = response.getWriter();
/** 反馈操作信息 */
writer.println("保存成功!");
writer.close();
}
/**
* The doPost method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to post.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
doGet(request, response);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -