📄 removemailservlet.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 com.lovo.service.IMailBo;
import com.lovo.service.IMailBoImpl;
public class RemoveMailServlet extends HttpServlet
{
/** 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/xml; charset=utf-8");
/** 设置响应头,让浏览器不缓存信息 */
response.setHeader("Cache-control", "no-cache");
/** 获得所有要删除的邮件id */
String mailIds = request.getParameter("mailIds");
/** 获得是否要彻底删除邮件 */
String thorough = request.getParameter("thorough");
/** 获得发送请求的页面名称 */
String whichPage = request.getParameter("whichPage");
/** 将邮件id转为int数组 */
String[] mailIdArray = mailIds.split(",");
int[] ids = new int[mailIdArray.length];
for(int i = 0; i < mailIdArray.length; i++)
{
ids[i] = Integer.parseInt(mailIdArray[i]);
}
String message = "";//存反馈信息
if(thorough.equals("true"))
{
/** 彻底删除邮件 */
mailBo.deleteMail(ids);
message = "信件已彻底删除";
}
if(thorough.equals("false"))
{
/** 把邮件改为已删除状态 */
mailBo.moveToDeleted(ids);
message = "信件已删除";
}
/** 获得输出流 */
PrintWriter writer = response.getWriter();
/** 构建xml */
writer.println("<?xml version='1.0' encoding='UTF-8'?>");
writer.println("<update>");
writer.println("<replyinfo>" + message + "</replyinfo>");
writer.println("<whichPage>" + whichPage + "</whichPage>");
writer.println("</update>");
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 + -