ITPub博客

首页 > 应用开发 > IT综合 > 在Web上登录Domino后直接打开用户的邮件 (转)

在Web上登录Domino后直接打开用户的邮件 (转)

原创 IT综合 作者:amyz 时间:2007-11-12 15:34:34 0 删除 编辑
在Web上登录Domino后直接打开用户的邮件 (转)[@more@]

/**
 *

Title: MailRedirectservlet


 *

Description: 登录domino服务器后直接打开用户邮件


 *

Copyright: Copyright (c) 2002 - 2003


 *

Company: Beyond DayBreak Office


 *

HomePage: http://202.101.111.1/123


 *

E-mail: .NET">mailto:YuLimin@163.net


 * @author YuLimin
 * @version 1.0
 */

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("直接打开登录用户的邮件开始!

");
  out.println("登录的用户名为:" + strFullName + "

");

  if(strFullName == null || strFullName.equalsIgnoreCase("Anonymous"))
  {
  out.println("没有登录到Domino服务器!

");
  }
  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 + "

");
  String strMailURL = request.getScheme() + "://" + request.getServerName();
  int strServerPort = request.getServerPort();
  if(strServerPort != 80)
  {
  strMailURL += ":" + strServerPort;
  }
  strMailURL += "/" + strMailFile;
  out.println("邮件地址为:" + strMailURL + "

");
  out.println("");
  //response.sendRedirect(strMailURL);
  //response.encodeRedirectUrl(strMailURL)
  }
  else
  {
  out.println("找不到 " + strFullName + " 的邮件文件

");
  }
  }
  catch(NotesException e)
  {
  out.println(e.toString() + "

");
  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服务器后直接打开用户的邮件!";
  }
}


来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/10752019/viewspace-981914/,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论
  • 博文量
    3984
  • 访问量
    7361823