• 如何在Notes中撰寫JavaServlet程式


    這是一個簡單的Servlet程式,主要動作為: 至names.nsf中抓取所有使用者的LastName,並Show在Browser上

    環境設定:

      1.安裝JDK1.2.2或更高版本

      2.classpath加入下列jar檔路徑:
        >>JSDK(jsdk.jar) : Domino R5目前提供2.0版的JSDK,它存放在Domino(Or Notes)的目錄下.亦可至Sun網站下載最新版本
        >>Domnio Java classes(Notes.jar) : 它存放在Domino(Or Notes)的目錄下.
        >>NCSO.jar : 如果您要使用Remote Access,必需加入此路徑,它存放在\data\domino\html\java目錄下.

      3.啟用支援Java Servlet:於伺服器文件>Internet通信協定>Domino Web引擎>Java Servlets設定,如下圖:


    開發程式:

      1.使用文字編輯工具撰寫下列程式,並儲存成ShowNames.java
        import java.io.*;
        import javax.servlet.*;
        import javax.servlet.http.*;
        import lotus.domino.*;

        public class ShowNames extends HttpServlet {

            public ShowNames() {
                super();
            }

            public void doGet(HttpServletRequest req, HttpServletResponse res) {
                try {
                    // set up HTML output format
                    res.setContentType("text/html");
                    PrintWriter out = res.getWriter();
                    out.println("<HTML");
                    out.println("<HEAD><TITLE>Contact List</TITLE></HEAD>");
                    out.println("<BODY>");

                    // initialize Notes access and get the People view in loacl address book
                    NotesThread.sinitThread();
                    Session s = NotesFactory.createSession();
                    Database db = s.getDatabase(null, "names.nsf");
                    View vw = db.getView("People");
                    // loop through each person document
                    Document doc = vw.getFirstDocument();
                    while (doc != null) {
                        out.println(doc.getItemValueString("LastName") + "<BR>");
                        doc = vw.getNextDocument(doc);
                    }
                    // finish off HTML document
                    out.println("</BODY></HTML>");
                } catch(Exception e) {
                    // print out errors to console and servlet Log (servlet Log output goes to Notes log)
                    e.printStackTrace();
                    getServletContext().log("Error: " + e.getMessage());
                } finally {
                    // clean up Notes
                    NotesThread.stermThread();
                }
            }
        }
       2.編譯程式:使用javac ShowNames.java 可得 ShowNames.class

       3.部署:將ShowNames.class檔copy至\data\domino\servlet下

       4.重新啟動 Http Service

    開始測試: 開起IE,並輸入http://localhost/servlet/ShowNames,此時是不是把通訊錄中的人員都列出來了呢^^

    附註: Domnio Java classes的使用方式請參照 Notes Help
    附加檔案
    ShowNames.java
  • 相关阅读:
    MySQL创建数据库简单命令
    工作的本质是解决问题
    使用消息中间件时,如何保证消息仅仅被消费一次?
    缓存穿透了怎么办?
    MySQL 数据库的提速器-写缓存(Change Buffer)
    删库了,我们一定要跑路吗?
    做好一件事的三要素
    一分钟简单了解 JSON Web Token
    聊一聊 MySQL 中的数据编辑过程中涉及的两阶段提交
    聊一聊 MySQL 数据库中的那些锁
  • 原文地址:https://www.cnblogs.com/hannover/p/1900560.html
Copyright © 2020-2023  润新知