向Domino Server添加数据

标题:向Domino Server添加数据
作者:Lee353086(kagula)
日期:2007-11-30

目的:通过列出步骤,说明如何向Domino Server添数据

环境:
[1]IBM JAVA JDK(From WebSphere6.1安装包中得到)
[2]Notes6.5(Server+Client)
[3]Tomcat4.x

内容摘要:
    第一部份:配置Notes要注意的地方。
    第二部份:一个jsp例子,说明如何向Domino Server添加数据。


正文:
    第一部份:配置Notes要注意的地方。
    [a-1]首先你要确保LDAP Server(Listen for connect requests on TCP Port:389)
       LDAP Server、DIIOP Server(Listen for connect requests on TCP Port:63148)
       HTTP Server(Listen for connect requests on TCP Port:80),它们已经正确启动。
    在Notes安装目录.../Lotus/Domino/notes.ini文件中找到ServerTasks这一行,确保内容如下:
    ServerTasks=Update,Replica,Router,AMgr,AdminP,CalConn,Sched,HTTP,IMAP,LDAP,POP3,DIIOP
    [a-2]为了验证 Domino Web 服务器正在运行,可打开浏览器并输入 URL:http://localhost。
         这应启动 Domino Web 服务器的开始页。
    [a-3]在安装,Notes的client的时候,请确认已经安装了Lotus Domino Administrator类组件,因
       为你需要通过它,来管理Domino服务器。
    [a-4]进入Lotus Domino Administrator界面
         [配置]->[当前服务器文档]->[DIIOP]->[Host name/address]把ip改为127.0.0.1

    第二部份:一个jsp例子,说明如何向Domino Server添加数据。
    [b-1]在你的tomcat4目录的/webapps下建立Lotus目录
    [b-2]在当前目录下建立MyJsp.jsp文件,内容如下
-------------------------------------------------------------------------------------------------------------------------
<%@ page language="java" pageEncoding="utf-8" import="java.net.*,java.io.*,java.util.*,javax.servlet.*,javax.servlet.http.*,lotus.domino.*"%>

<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
 <base href="<%=basePath%>">

 <title>This is a Notes Example starting page</title>
 
 <meta http-equiv="pragma" content="no-cache">
 <meta http-equiv="cache-control" content="no-cache">
 <meta http-equiv="expires" content="0">   
 <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
 <meta http-equiv="description" content="This is my page">
 <!--
 <link rel="stylesheet" type="text/css" href="styles.css">
 -->

</head>
 
<body>
  <center><h3>Notes program</h3></center><br>
<%  
       String subject=request.getParameter("subject");
       String body=request.getParameter("body");

       if((subject!=null)&&(body!=null)&&(subject.length()>0)&&(body.length()>0))
       {  //begin record
      
      
      Session nses=null;
           try {
        String svr = "127.0.0.1"; //10.19.21.108
    String user = "jun";  //Domino Server's Administrator account name
    String pwd = "12345678"; //According above,it's password.
    String dbname = "Lastdomi.nsf"; //Lastdomi.nsf  log.nsf
    //out.println("user="+user+",pwd="+pwd+",dbname="+dbname+"<br/>");
    nses = NotesFactory.createSession(svr, user, pwd);
    Database db = nses.getDatabase("", dbname); 
      //out.println("GET DB CONNECTION");
    if (!db.isOpen()) {
     db.open(); 
    }
    
       Document doc = db.createDocument();


       doc.replaceItemValue("Subject", subject);
       doc.replaceItemValue("Body", body);
       doc.replaceItemValue("AbbreviateFrom", "kagula");
       doc.replaceItemValue("AbrFrom", "kagula__TRS");
       doc.replaceItemValue("AltFrom", "CN=kagula/O=TRS");
       doc.replaceItemValue("AltLang", "utf-8");
       doc.replaceItemValue("From", "CN=kagula/O=TRS");
   
        doc.save(true);
        out.println("<font color=#ff0000>The record has beed added</font>");
   } catch (NotesException ne) {
    ne.printStackTrace();
    throw new ServletException("Notes error1: " + ne.id + " " + ne.text);
   } finally {
    if (nses != null) {
     try {
      nses.recycle();
     } catch (NotesException ne) {
      ne.printStackTrace();
      throw new ServletException("Notes error2: " + ne.id + " " + ne.text);
     }
       }//END FINALLY
 }

  }//end record
  %>
  <form action="MyJsp.jsp" method="post">
    <center><table border="1">
      <tr>
         <td>Subject:</td><td><input type="text" name="subject"/></td>
       </tr>
      <tr>
           <td>Body:</td><td><textarea name="body" cols="45" rows="9"></textarea></td>
      </tr>
      <tr>
           <td></td><td align="right"><input type="submit" value="submit"/></td>
      </tr>
   </table></center>
  </form> 
</body>
</html>
-------------------------------------------------------------------------------------------------------------------------
     [b-3]在当前目录下建立WEB-INF目录,在WEB-INF目录下建立web.xml文件,内容如下
          可能你需要添加过滤器,使这个例子支持中文信息(utf-8)提交。
-------------------------------------------------------------------------------------------------------------------------
<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE web-app
    PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
    "http://java.sun.com/dtd/web-app_2_3.dtd">

<web-app>
  <display-name>Welcome to Tomcat</display-name>
  <description>
     Welcome to Tomcat
  </description>
</web-app>
-------------------------------------------------------------------------------------------------------------------------
     [b-4]在WEB-INF目录下,建立lib目录,里面放置Notes.jar(如果服务器和客户端不在同一个物理机器上,你可能需要NCSO.jar替换它)
         这些jar文件,你可以在你的Notes安装目录中找到。例如Notes.jar一般放在.../Lotus/Domino目录下。
     [b-5]现在让我们回过头来总结下Lotus项目文件清单:
       [b-5-1]MyJsp.jsp(程序文件)
              WEB-INF/web.xml(配置文件)
              WEB-INF/Notes.jar(调用包)
     [b-6]设置bin/catalina.bat文件,JAVA_HOME环境变量的设置,让它指向IBM JDK。
     [b-7]使用LotusNotes6.5登录后,在你的服务器(在这里,记住要选择你的计算机名称)数据库菜单上新建Lastdomi.nsf文件
          (用Discussion -- Notes and Web from Release 6模板建这个文件)。
     [b-8]先启动Domino server再启动Tomcat4、然后,通过浏览器再访问MyJsp.jsp就可以了。


参考网站:
[1]《Building a J2EE application with Domino and WebSphere》
https://www6.software.ibm.com/dw/education/ls/lsj2ee/index.html

[2]《Lotus Domino 和 IBM WebSphere 集成解决方案: Domino JSP 标签库》
http://www.ibm.com/developerworks/cn/lotus/dwintegration-jsp/

[3]《Using Java to communicate between Lotus Domino and IBM WebSphere Application Server on iSeries》
http://www.ibm.com/developerworks/eserver/articles/using_java.html

备注:
[1]在DominoServer的http服务启动后,你也可以通过URL http://localhost/  寻找帮助信息。 

你可能感兴趣的:(向Domino Server添加数据)