📄 inbox.java
字号:
/*
* This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/).
*/
package ch05.controller;
import java.io.*;
import java.util.Hashtable;
import javax.servlet.*;
import javax.servlet.http.*;
import ch05.*;
import ch05.module.*;
/**
* 针对收件箱页面的Servlet
* @author ShenYK
* @version 1.0
*/
public class Inbox extends HttpServlet
{
public void doGet ( HttpServletRequest request,
HttpServletResponse response )
throws ServletException, IOException
{
//设置提交表单的中文编码
request.setCharacterEncoding("GBK");
HttpSession mySession = request.getSession(true);
//清空错误消息
mySession.setAttribute("errMsg","");
//是否非法进入本页面
if ( mySession.getAttribute("username") == null )
{
response.sendRedirect("/ch05/login.jsp");
return;
}
//是否进入默认页面
if ( !request.getParameterNames().hasMoreElements() )
{
//设置session中的页面值域
mySession.setAttribute(CommonConst.VIEWID_INBOXLIST, new Hashtable() );
//取得最新邮件
MInbox mInbox = new MInbox();
boolean bGetResult = mInbox.getNewestMail( mySession );
mySession.setAttribute("curPage","inbox");
response.sendRedirect("/ch05/inbox.jsp");
return;
}
//得到用户输入信息
String sMailIndex = request.getParameter("mailIndex");
String sMailOption = request.getParameter("mailOption");
//如果用户是提交表单
if ( sMailIndex != null && sMailIndex.length() > 0 )
{
//设置session中的详细页面值域
mySession.setAttribute(CommonConst.VIEWID_INBOXDETAIL, new Hashtable() );
//获得对应的邮件信息
MInbox mInbox = new MInbox();
boolean bGetResult = mInbox.getDetailMail( mySession, sMailIndex );
if ( bGetResult )
{
response.sendRedirect("/ch05/inboxDetail.jsp");
}
else
{
response.sendRedirect("/ch05/inbox.jsp");
}
}
//如果用户是从详细页面迁移过来的
else if ( sMailOption != null && sMailOption.length() > 0 )
{
String sSender = request.getParameter("sender");
String sSendTime = request.getParameter("sendTime");
String sSubject = request.getParameter("subject");
String sContent = request.getParameter("content");
//删除邮件
if ( sMailOption.equals("delete") )
{
MInbox mInbox = new MInbox();
boolean bDeleteResult = mInbox.deleteMail( mySession, sSender, sSendTime );
mInbox.getNewestMail( mySession );
response.sendRedirect("/ch05/inbox.jsp");
return;
}
//回复邮件
else if ( sMailOption.equals("reply") )
{
//设置session中的写邮件页面值域
mySession.setAttribute(CommonConst.VIEWID_SENDBOXDETAIL, new Hashtable() );
MInbox mInbox = new MInbox();
boolean bReplyResult = mInbox.replyMail( mySession, sSender, sSubject, sContent );
mySession.setAttribute("curPage","composite");
response.sendRedirect("/ch05/composite.jsp");
return;
}
}
//如果用户非法进入这个页面
else
{
response.sendRedirect("/ch05/login.jsp");
}
}
public void doPost ( HttpServletRequest request,
HttpServletResponse response )
throws ServletException, IOException
{
doGet( request, response );
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -