📄 common.java
字号:
/*
* This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/).
*/
package webMail.controller;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
/**
* 针对所有页面的共同Servlet
* 执行例如功能页面的跳转、退出登录等功能
* @author ShenYK
* @version 1.0
*/
public class Common 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("../VWebMail.jsp");
return;
}
//是否进入默认页面
if ( !request.getParameterNames().hasMoreElements() )
{
response.sendRedirect("../VWebMail.jsp");
return;
}
//得到用户输入信息
String sGotoPage = request.getParameter("gotoPage");
String sLogout = request.getParameter("logout");
//用户是否要退出登录
if ( sLogout != null && sLogout.equals("yes") )
{
//清除session,并且退回到login画面
mySession.invalidate();
response.sendRedirect("../VWebMail.jsp");
return;
}
//如果登录有效,则继续进行页面跳转
if ( sGotoPage != null )
{
//收件箱
if ( sGotoPage.equals("CInbox") )
{
//mySession.setAttribute("curPage", "CInbox");
response.sendRedirect("CInbox");
return;
}
//写邮件
else if ( sGotoPage.equals("CComposite") )
{
//mySession.setAttribute("curPage", "CComposite");
response.sendRedirect("CComposite");
return;
}
//发件箱
else if ( sGotoPage.equals("CSendbox") )
{
//mySession.setAttribute("curPage", "CSendbox");
response.sendRedirect("CSendbox");
return;
}
//地址簿
else if ( sGotoPage.equals("CAddress") )
{
//mySession.setAttribute("curPage", "CAddress");
response.sendRedirect("CAddress");
return;
}
//邮箱设置
else if ( sGotoPage.equals("CSetting") )
{
//mySession.setAttribute("curPage", "CSetting");
response.sendRedirect("CSetting");
return;
}
else
{
//mySession.setAttribute("curPage", "login");
response.sendRedirect("../VWebMail.jsp");
return;
}
}
else
{
//清除session,并且退回到login画面
mySession.invalidate();
response.sendRedirect("../VWebMail.jsp");
return;
}
}
public void doPost ( HttpServletRequest request,
HttpServletResponse response )
throws ServletException, IOException
{
doGet( request, response );
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -