欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

在Web上登录Domino后直接打开用户的邮件 WebLotusServletOffice配置管理 

程序员文章站 2022-06-03 11:21:22
...

/**
 * <p>Title: MailRedirectServlet</p>
 * <p>Description: 登录Domino服务器后直接打开用户的邮件!</p>
 * <p>前提Domino配置成支持servelt,</p>
 * <p>打开Names.nsf,配置,服务器文档,Internet协议,Domino Web引擎,Java 服务器小程序,选择:Domino 服务器小程序管理器</p>
 * <p>保存后重启Domino</p>
 * <p>把这个编译后的.class文件放到%DOMNIO%\Data\Domino\servlet目录下面</p>
 * <p>然后通过http://%SERVER%/servlet/MailRedirectServlet访问即可</p>
 * <p>Copyright: Copyright (c) 2001 - 2004</p>
 * <p>Company: Beyond DayBreak Office</p>
 * <p>HomePage: http://202.101.111.1/123</p>
 * <p>E-Mail: YuLimin@163.net</p>
 * @author YuLimin
 * @version 1.0
 */

//package net.echochina.oa;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import lotus.domino.Document;
import lotus.domino.NotesException;
import lotus.domino.NotesFactory;
import lotus.domino.NotesThread;
import lotus.domino.Session;
import lotus.domino.View;

public class MailRedirectServlet extends HttpServlet
{
    final static String DB_NAMES = "Names.nsf";

    public MailRedirectServlet()
    {
    }

    public void init() throws ServletException
    {
    }

    public void destroy()
    {
    }

    public void doGet(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException
    {
        doPost(request,response);
    }

    public void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException
    {
        String strFullName = request.getRemoteUser();
        String strMailFile = "";

        response.setContentType("text/html; charset=gb2312");
        ServletOutputStream out = response.getOutputStream();
        out.println("直接打开登录用户的邮件开始!<p>");
        out.println("登录的用户名为:" + strFullName + "<p>");

        if(strFullName == null || strFullName.equalsIgnoreCase("Anonymous"))
        {
            out.println("没有登录到Domino服务器!<p>");
            out.println("<script>document.location='/Names.nsf?Login&RedirectTo=/servlet/MailRedirectServlet';</script>");
        }
        else
        {
            NotesThread.sinitThread();
            Session session = null;
            View view = null;
            Document doc = null;
            try
            {
                session = NotesFactory.createSession();
                view = session.getDatabase(session.getServerName(),DB_NAMES).getView("People");
                doc = view.getDocumentByKey(getShortName(strFullName));
                if(doc != null)
                {
                    strMailFile = doc.getItemValueString("MailFile");
                    strMailFile = strMailFile.replace('\\','/');
                    if(!strMailFile.toLowerCase().endsWith(".nsf"))
                    {
                        strMailFile += ".nsf";
                    }
                    out.println(strFullName + "用户的邮件为:" + strMailFile + "<p>");
                    String strMailURL = request.getScheme() + "://" + request.getServerName();
                    int strServerPort = request.getServerPort();
                    if(strServerPort != 80)
                    {
                        strMailURL += ":" + strServerPort;
                    }
                    strMailURL += "/" + strMailFile;
                    out.println("邮件地址为:" + strMailURL + "<p>");
                    out.println("<script>");
                    //out.println("alert('开始进入邮件')");
                    out.println("document.location='" + strMailURL + "'");
                    out.println("</script>");
                    //response.sendRedirect(strMailURL);
                    //response.encodeRedirectUrl(strMailURL)
                }
                else
                {
                    out.println("找不到 " + strFullName + " 的邮件文件!<p>");
                }
            }
            catch(NotesException e)
            {
                out.println(e.toString() + "<p>");
                e.printStackTrace();
                System.out.println(e.id + " " + e.text);
            }
            finally
            {
                try
                {
                    if(doc != null)
                    {
                        doc.recycle();
                        doc = null;
                    }
                    if(view != null)
                    {
                        view.recycle();
                        view = null;
                    }
                    if(session != null)
                    {
                        session.recycle();
                        session = null;
                    }
                }
                catch(Exception e)
                {
                    e.printStackTrace();
                }
                NotesThread.stermThread();
            }
        }
        out.close();
    }

    //取用户的短名!
    private String getShortName(String strTemp)
    {
        if(strTemp.indexOf("CN=") >= 0 && strTemp.indexOf("/") >= 0)
        {
            return strTemp.substring(3,strTemp.indexOf("/"));
        }
        else
        {
            return strTemp;
        }
    }

    public String getServletInfo()
    {
        return "登录Domino服务器后直接打开用户的邮件!";
    }
}