logo

Creating servlets inside the Domino Designer

According to an article on Notes.net's Iris Today webzine about developing servlets for Domino:

The standard Domino Designer development environment does not support the development of servlets, so you must use a third-party IDE or the SUN command-line JDK to develop servlet code


It may not be supported but that is not to say you can't do it. Imagine you don't have the luxury of a 3rd party IDE on your machine. This article helps by explaining how you can develop servlets from within the Domino Designer IDE.

First of all, the classes that we are going to use are contained in a file called jsdk.jar, which should be in the root of your Lotus Domino directory. To use these classes you could simply include it in your agent, but the best thing to do is to place this in a Script Library before we start creating the servlet.

Creating a ServletSupport Script Library
  • Create a new Script Library
  • Change the type of the library to Java
  • Press the "Edit Project" button
  • Select "Local Filing System" at the "Browse" label
  • Browse to the root of the Lotus Domino directory
  • Select "Archive" in "Show file types".
  • Select jsdk.jar and click "Add/Replace File(s)".
The jsdk.jar file should now be included in the Script Library list to the right, like below:

Image

Finish off by pressing "OK" in dialog box then closing and saving the Script Library, calling it something like "ServletSupport".

Creating an agent that uses this Script Library
  • Create a new Java agent
  • Press "Edit Project"
  • Choose "Shared Java Libraries" at the "Browse" label
  • Choose the Script Library you just created ("ServletSupport")
  • Press the "Add/Replace File(s)" button
  • Press "OK" in the dialog box
Creating the code for the servlet

Now comes the interesting part. Remove ALL the code that Domino has automatically generated from the agent. Replace it with this code that will create a fairly simple servlet:

import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.*;
import javax.servlet.http.*;

/**
* Simple servlet that only outputs a simple string when called.
*/
public class MyServlet extends HttpServlet {

/**
* Called when the HTTP task is starting.
* Initialize database (JDBC) connections etc. here.
*
* @param config the ServletConfig object passed by the servlet container.
*/
public void init(ServletConfig config) {
System.out.println(this.getClass().getName() + " initialized");
}

/**
* Called when a user makes a HTTP GET, with a URL.
*
* @param request the request of the client.
* @param response the response that should be sent to the client.
*/
public void doGet(HttpServletRequest request, HttpServletResponse response) {
try {
PrintWriter out = response.getWriter();
out.println("doGet in " + this.getClass().getName() + "entered");
} catch(IOException e) {
//Something went wrong.
e.printStackTrace();
}
}

/**
* Called when a user makes a HTTP POST from a HTML form.
*
* @param request the request of the client.
* @param response the response that should be sent to the client.
*/
public void doPost(HttpServletRequest request, HttpServletResponse response) {
try {
PrintWriter out = response.getWriter();
out.println("doPost in " + this.getClass().getName() + "
entered");
} catch(IOException e) {
//Something went wrong.
e.printStackTrace();
}
}

/**
* Called when the HTTP task is shut down.
* Always close open database (JDBC) connections etc. here.
*/
public void destroy() {
System.out.println(this.getClass().getName() + " destroyed");
}
}


Give the agent a name such as "MyServlet" and compile it (don't close the agent yet!). It should look something like:

Image

Now here is the trick. When you compiled the code Domino Designer created a .java and a .class file in the TEMP directory of your operating system (usually "C:\Temp").

Inside the TEMP directory, the Designer creates folders named "jarXXXXX.dir", where XXXXX is a number. In one of these directories, a class-file with the name "MyServlet.class" should exist, as shown below:

Image

Make a copy of this file and paste it in to the "servlet" directory of the Domino server on which you want it to run. Restart the server's HTTP task and you can then start to use your servlet.

At this point you could of course throw this agent away. We only used it to create our .class file. It may be worth keeping it though in case you need to make any changes to the servlet in the future.

This article assumes that you have already set up the server to run Java servlets. If you haven't then this article on Notes.net describes how. There is also plenty of help in Domino's help files.

So there we have it. You can develop servlets in the Desiger after all. If, however, you see no point and would rather write the servlets in a 3rd party IDE then here is an article from Notes.net describing how.

Feedback

  1. Javax.swing.*

    I think this is great, I have tried it and it works very well. Have you tried it with other javax.swing classes such as JOptionPane

    1. Re: Javax.swing.*

      I tried created my own *.jar containing the proper classes and I could not get it to work. I guess this one will have to wait to Rnext is released

    2. Re: Javax.swing.*

      To be honest. No I haven't tried that.

      I myself am a newby to servlets and fairly new to Java. The article was kindly written by Johan Känngård.

      Drop me a line if you have ideas for creating something fancy that we can all benefit from. That goes for the rest of you as well! This site can't survive forever on my contribution alone ;-)

      Jake -CodeStore

    3. Re: Javax.swing.*

      Uh, keep in mind that the java.swing classes are front end (applet) classes, not back end (servlet) classes.

      Show the rest of this thread

  2. Using the Swing classes in the Notes client

    I DID IT !!!!

    Please post this tip.

    Download JFC 1.1.

    1. Click on Create Agent 2. Chose Java 3. Click on the Edit Project. 4. Navigate to the directory you unziped your JFC. 5. Add BeanInfo. jar, multi.jar, swingall.jar, swing.jar and windows.jar; 6. Click on OK to close the project.

    Now here is the simple code that I used.

    import lotus.domino.*; import javax.swing.*; import java.awt.*;

    public class JavaAgent extends AgentBase {

    public void NotesMain() {

    try { Session session = getSession(); AgentContext agentContext = session.getAgentContext(); JOptionPane.showMessageDialog(null, "Javax.swing will work"); // (Your code goes here)

    } catch(Exception e) { e.printStackTrace(); } } }

    Thanks for the intial idea with the servlets example. There is one caveat it is kind of slow.

    1. Re: Using the Swing classes in the Notes client

      Hi Troin,

      Thanks for all the feedback. Working alone I doubt I'd be able to make make this site survive.

      However, the site is aimed *purely* at web development and as far as I can see your tip that you reqeusted posting is client based. Let me know if I'm being an ignoramous and if you fancy becoming a "contributing editor"..... mail me on the above address.

      Jake -CodeStore

  3. A much easier way to get at the executables

    From the Java Script Library IDE, click the export button. It creates a <servletname>.jar file in the directory you specify. I've not actually tested to confirm that this works without any problems, but certainly seems logical, and it's easier than hunting around in temp files! :-)

    Please, though, if anyone finds a drawback to using this method I would appreciate hearing about it.

    1. Re: A much easier way ... My mistake

      Ooops. It just creates a .java file of the agent's java code. My mistake.

    • avatar
    • jpg
    • Fri 23 Nov 2001

    Get the executable: A SOLUTION

    In orger to get the servlet jar without messing with temporary files, do the following:

    Create a new lotuscript agent in the database holding the servlets. Call it getJar. Paste the following code in the initialize method, modify the aDir$ and aPath$ variable to match your installation (write permission needed) and you're done.

    Call this agent from a browser: http://yourServer/yourBase/getJar

    Fill the notesID (get it in agent property), return and save the JAR...

    --CUT-------------------------------------

    On Error Goto trapError Dim session As New NotesSession Dim db As NotesDatabase Dim collection As NotesDocumentCollection Dim doc As NotesDocument Dim docCtx As NotesDocument Dim item As Notesitem Print "Domino Servlet Code Extractor v001 - JwH<br>" aDir$="E:/lotus/domino/simu/data/domino/html" aPath$="/" Set docCtx = session.DocumentContext ret%=Instr(docCtx.Request_Content(0),"=") If(ret%<>0 And Len(docCtx.Request_Content(0))>ret%) Then Set db = session.CurrentDatabase Set doc = db.GetDocumentByID(Mid$(docCtx.Request_Content(0),ret%+1)) If ( Not(doc Is Nothing)) Then Set item=doc.getfirstItem("$TITLE") If ( Not(item Is Nothing)) Then Dim object As NotesEmbeddedObject Set object = doc.GetAttachment( "%%object%%.jar" ) If ( Not(object Is Nothing)) Then object.extractfile(aDir$+aPath$+item.Text+".jar") Print "Agent: <b>"+item.Text+"</b>, <i>"+Cstr(object.filesize)+"</i> bytes written <a href="+aPath$+item.Text+".jar>here</a>.<br>" Else Print "<b>"+Mid$(docCtx.Request_Content(0),ret%+1)+"</b>: ** Valid NotesID, good agent, but not compiled ?" End If Else Print "<b>"+Mid$(docCtx.Request_Content(0),ret%+1)+"</b>: ** Valid NotesID, but not an agent ?" End If Else Print "<b>"+Mid$(docCtx.Request_Content(0),ret%+1)+"</b>: ** Invalid NotesID, &gt;&gt; Agent properties &gt;&gt; Last tab &gt;&gt; Last line (NT0000XXXX)" End If End If finito: Print |<br><form action="getJar?openagent" method="post" enctype="multiform/form-data">| Print |<b>NotesID of Agent</b>: &nbsp;NT<input type=text name=nid size=8> (forget leading 0s)| Print |</form>| Print |<script>document.forms[0].nid.focus()</script>| Exit Sub trapError : Print "<br>***Erreur ["+Cstr(Err)+"] " + Error + " at line: "+ Cstr(Erl) +"<br>" Resume finito

    --CUT-------------------------------------

    Hope that helps -jpg

    1. Re: Get the executable: A SOLUTION

      So why not use:

      http://<server>/<database.nsf>/<agent>/$FILE/%%object%%.jar?OpenElement

      ... if the server admin has forgot to redirect the *%%object%%.jar* URL.

      - Johan

    • avatar
    • Ian Sherwood
    • Fri 18 Oct 2002

    Let ServletMaid deploy your servlet

    For a complete (free) solution to deploying servlets you've written in Domino, see the "ServletMaid" project at http://www.OpenNTF.org

    ServletMaid 1.0 has just been released. ServletMaid can automatically extract your agent and scriptlibrary .jars as well as other file types like images, servlet.properties, etc. and can place them wherever you please.

    Enjoy, Ian

    1. Re: Let ServletMaid deploy your servlet

      Where is ServletMaid? It seams to have been removed from OpenNTF.org!

      MARK

      Show the rest of this thread

  4. Creating servlets inside the Domino Designer

    hi buddy, this is really classic article.....i needed something like this badly.....b'coz i am a java fan....and currently working on lotus domino.... any way if someone can guide to emebbed jsp in lotus domino......mean something exactly like this for JSP development.......

    thanx & regards SG

  5. thanks

    Hi, thanks for your good article, If u have any articles on domino-servlets & domino-webservies please post me the details.

    • avatar
    • VijayK
    • Wed 30 Dec 2009

    I found your article very useful to get started.

    but I am confused at one point.

    Java Agent will be installed per user. So every user will install Java Agent on their machine to server. do they need to follow all of the above procedure?

    After compiling it will create .class file and it needs to be copied on domino server servlet directory.

    So, if I want to make multiple users to use my agent. all users needs to copy .class file on servlet directory and there might be problem as on the server that .class file going to be exist for other user.

    Please tell me how can i get out of this confusion? as I am new to domino server and its development.

    And How can I make user to log in from servlet.

    Thanks

Your Comments

Name:
E-mail:
(optional)
Website:
(optional)
Comment:



Navigate other articles in the category "Java"

« Previous Article Next Article »
Creating an Email Java Class   At last, an applet worth using

About This Article

Author: Jake Howlett
Category: Java
Hat Tip: Johan Känngård of WM-data
Keywords: servlet; class; designer;

Attachments

MyServlet.java (2 Kbytes)

Options

Feedback
Print Friendly

Let's Get Social


About This Website

CodeStore is all about web development. Concentrating on Lotus Domino, ASP.NET, Flex, SharePoint and all things internet.

Your host is Jake Howlett who runs his own web development company called Rockall Design and is always on the lookout for new and interesting work to do.

You can find me on Twitter and on Linked In.

Read more about this site »