PreviousNext…

You, me, Domino and JSP

Background

I am so foolish. Yonks ago, Jake published a blog entry about the future of Domino. There was some kind of Domino / car analogy which was most amusing. Great stuff. Why I'm less sure about referring you to this blog entry is the fact that some muppet called "Ben Poole" posted a ludicrously over-blown, cretinous and poorly thought-out comment (I know! Can you believe it?!?) regarding Lotus Advisor magazine's credentials. Well, I "kind of" stand by my comments with regards the magazine (it had its moments, but IMHO, The View does it better), but I take back any inference that Bob Balaban's article, as referenced in the blog entry, was rubbish. Anything but. I whole-heartedly agree with what he says. I link to a couple of his articles in the "Further reading" section below, but my specific reference for this piece is JSPs: A Total Waste of Time? At the time, I had been drawn into the whole "J2EE is it" hype that was going round, without having tried to use any of it in anger. Tsk.

JSP

Enough mystery. Essentially (and I hope I don't do Bob's arguments a disservice), Bob takes issue with the design of Java Server Pages and how they compete badly with Microsoft's ASP technology, ignoring what Domino brings to the table. He's not happy with the implementation of JSP technology, nor with the developer tools available (a decent JSP debugger anyone?)

OK, so we all know about workflow, security, easy collaboration-oriented processes, and so on. How's about @formula? Domino forms? Lotusscript? Crikey, controversial. but they're not that bad for web apps. Really. Hacks an' all. OK, so you couldn't run Amazon with that technology, but you get my meaning. ;-)

Anyway, back to the article: fair points, well made. In fact, Bob put together a very interesting demo website, which I saw at The View Domino Technical Conference in Amsterdam. The application enabled web users to register for courses offered by the site. The system needed to be able to handle class schedule conflicts, whilst also checking for full / cancelled courses and dealing with all the admin stuff such as mailing out confirmations and so on. Bob's design was divided between Domino and Websphere. Domino handled the initial forms presented to the user, whilst servlets hosted in Websphere took care of the heavy duty legwork. The servlets then left Domino to do the lighter "background" work: workflow, automatic emails, and so forth. "Appropriate technology" is a term I first came across in secondary school geography lessons. It seems to apply well here too.

Me: getting into JSPs

I started really getting into JSPs by accident. I've always maintained that for me, and no doubt for many other coders, the only way to get your head around a new product / language / object model / whatever, is to "use it in anger." Reading the specs and playing with demos are worthwhile activities to a point, but ultimately they don't cut it for me. It wasn't until I had to bring some Notes-based data into a JSP-based web system that I really started looking at JSP, JDBC, XML, Domino Java objects, servlets, etc., etc.

A simple JSP project

In the end, having examined connecting to a Notes data source in a variety of ways, I settled on a very simple approach: using Domino as an HTML data store, and having the JSP query and present the data. Here's the scoop, for what it's worth!

I use two JSP files; one as an "entry point" to the application, which then "posts" to the second JSP. The first file is very light (to be presented in a "portal" application, contained on a page with Lord knows how many other JSPs), whereas the second page contains HTML fetched from a Domino back-end. JSPs are essentially servlets, so one thing that's nice and easy in 'em is posting — all file two has to do is execute request.getParameter("winkle"), to find out what's being posted to it.

Using Domino

My pages provide the user with some drop-down lists; their selections then drive the presentation of additional content. These selections are composed entirely within Domino. We all know how Domino can serve up views as HTML. So, why not take a view consisting of document categories, and wrap these categories in <select> tags? Job done there.

Dynamic presentation

OK, so we have a category selected in an HTML form within a JSP (!). Now, we need to feed that selection through to something that can present us with data. This is where HTML form posting comes in. This time the JSP posts to itself (although of course it doesn't have to, it can post anywhere). Again, using the request model, we can grab the selected value, and use that to drive some HTML, be it in fields or whatever. As a simple example, we can dynamically set a value in a form field within a JSP thus:

<%
	String myValue = request.getParameter("winkle");
	String otherValue = request.getParameter("shrimp");
%>

<form name="…>
	<input type="text" name="myField" value="<%=myValue%>" />
</form>

Taking this principle further, let's build a URL, and then using the Java URLConnection class, connect to that URL:

import java.net.*;
import java.util.*;
import java.io.*;

public class GetWebPage	{
	public static void main(String args[])	{
		InputStreamReader in;
		BufferedReader br;
		String strURL = "http://www.site.com";
		String line;
		StringBuffer buff = new StringBuffer();
		URLConnection conn = null;

		try {
			URL urlThis = new URL(strURL);
			conn = urlThis.openConnection();
			conn.connect();
			in = new InputStreamReader(
			conn.getInputStream());
			br = new BufferedReader(in);

			while((line = br.readLine()) != null)
				buff.append(line + "\n");
				String txt = buff.toString();
				System.out.println(txt);
		} catch (IOException e)	{
			System.out.println("Doh! IO error: "
			+ e.getMessage());
		}	// End try catch
	}	// End main method
}	// // End overall class

Easy! Obviously this is just a stand-alone example in its own class (paste it into a text editor and save it as GetWebPage.java — you can then run it), and you need to tweak it to use it in some JSP code (er.. make the URL useful too!).

Let's move on: the problems

OK, so there's some code. You can use Domino URLs, building them programmatically in your JSPs from user selections and so forth, and then connect to those URLs. The results can be parsed to a String object (as above) and that object can in turn be passed back to the JSP. Nice 'n' easy. But think: you can do all that in Domino with a simple form and embedded view! No Java required! Heh. OK, so where do we start to run into problems with JSPs?

  • Debugging
  • JSPs are tricky buggers! Debugging is a nightmare. If, like me, you have to code your JSPs in some kind of shared development environment, chances are life will be doubly hard. Make sure you have server rights, because in order to develop JSPs halfway effectively, I would argue that you must have access to the working directory.

    Why is this directory important? Fire up Tomcat or similar, create some JSPs, and take a look at your WORK directory (location varies depending on the installation / J2EE server; have a root around). This directory stores all the "mid-point" Java files that your JSP engine generates. To explain further, JSPs get converted into a number of servlet Java files, which in turn get compiled. The "mid-point" files are the servlet Java files. Being able to access these helps immeasurably in terms of figuring out where the JSP engine has choked on your code.

  • What's going on?
  • Java is not a tagging language, it's a fully-featured programming language. As you can imagine from the code snippets above, my actual JSP code was long and hardly "tag-based." This is a draw-back, no question!

    JSPs were designed, as their acronym suggests, as direct counterparts to Microsoft's ASP technology. ASPs are typically built with VBScript and / or Javascript. Again, as the terms suggest, these are scripting languages. Whereas Java, the language of choice for JSPs, is precisely the opposite! This is why we've ended up with tag libraries and wot-not.

    As Marc Hedlund says:

    JSP has this nice impulse to take Java code out of HTML pages and put it into JavaBeans or other Java classes, where it belongs, so the HTML author doesn't need to know Java. Great, that's great. Unfortunately, the 'not Java' that is included in the HTML page is completely alien to (most) HTML authors.

    The best guide I've found for debugging JSP technology is over at the Sun Java developer site. The page in question is all about the book Professional JSP (2nd Edition) by Casey Kochmer, Geert Van Damme et al. A couple of specimen chapters are linked from the book's home page. The one you're after is Chapter 19, "Debugging JSP & Servlets", (link goes directly to a 295 KB PDF file).

    This could go on

    I'm not going to go on ad nauseam about JSP technology. Who am I to preach sermons anyway. The bottom line is I think it has its place, and it's a useful technology, but don't get swept away by the hype and the buzzwords like I did, especially if you're a Domino developer (if you're reading this site I guess you are!) A well-designed and coded Domino site can work so well, and the platform gives you so much "out of the box", you'd be daft to throw it all away just 'cause your boss likes the sound of "J2EE", "JSP", "Enterprise Java Beans" etc. [smiley RollEyes]

    Let the discussion begin…

    Further reading

    Comments

    1. I agree that JSPs are not a great technology. If you want to see what I believe is the "correct" solution for the separation of the presentation layer and the application logic, look at a "template engine" like WebMacro (http://www.webmacro.org).

      This is what JSPs should have been. I actually had a site that started as a Domino site, which I migrated to a Tomcat/Servlet/WebMacro based site based on the fact that I couldn't get anyone to develop the ui on Domino. In the past, I simply had them furnish pictures of the end product, which I then replicated my own way in Domino for the actual implementation. This makes it difficult to change the look and feel. It means more pictures from the UI guy which I have to translate into Domino Designer.

      The requirements for this solution was a site where the look and feel could be altered on a regular basis via a well known design tool (DreamWeaver) without affecting the application logic. That's when my path led me to WebMacro's homepage. My only gripe with WebMacro is that when using a tool like DreamWeaver, it stumbles a bit on the dynamic elements. Not bad enough that it bothers me, since I tend to do more handcoding anyway, but if you have one of those (all too common) finicky UI designers, they might get irked.

      WebMacro does a decent enough job of staying out of the way that you can usually get away with it. I keep hoping that someone will write a DreamWeaver extension for WebMacro, my list is so long that I would have to add it to the hundred other things I haven't done yet.

      Ed Wrenbeck#
    2. Dear Ben, I think I thorougly read your article but I still do not get it. You comment mentioning that I can do all this inside domino (form and embedded view) just emphasize my opinion that I am being forced to use a technology because it is en vogue. Looking at the debugging problem how neat would it be to have Garnet inside D6.

      Okay it has been mentioned that garnet did not provide a standard solution to deal with jsp but when I read this article I would really prefer the Domino approach. Unfortunately my current job situation is worse. Although still being employed I have to find fast solutions for real problems (RAD at its best with end date of yesterday). It is hard for me to keep up with technologies because they tend to cause overhead in my current situation.

      I much appreciate your approach to shed some light on the Domino and jsp situation. I will rest for a while and read it again maybe tomorrow (and the links you provided). Having said this you should never give a cent on my opinion. My thoughts are full of scepticism and only because I do not understand the Websphere and JSP hype does not mean this this bad technology.

      Henning Heinz#
    3. It's not bad technology, but like anything it can be abused. I always think it's good to keep up with the latest stuff, but a healthy amount of scepticism doesn't hurt!

      I don't blame you for finding the article hard to read though… like I say, it's just a load of thoughts on "paper" at the moment. I'm still formulating a full opinion when it comes to JSPs. I do like Java though.

      Ben Poole#
    4. The nice thing about JSP verses Servlets or Java Agents, is that you have a little bit (or lot) of Java code in what is essentially anHTML page, whereas outputting HTML strings from a Servlet or Java Agent is arduous. It's a pity the servlet engine wasn't updated in ND6 to support a higher JSDK, because the only place I know where Notes Agents fall down, is they cannot get a handle to HTTPServletRequest, and thus cannot access POST data. So a servlet does nicely in this instance.

      There's a feature I remember the JDK or JSDK didn't support in R5, about doing includes, and I can't find what it was in the JSDK documentation, so maybe it was in the JDK, and perhps supported now in ND6. I don't remember the specifics and need to get back to work.

      Really enjoy the discussion, though.

      Neill Laney#
    5. Re the amount of Java in your HTML, that's true — I can envisage how you could just have a couple of tags in a page that essentially call a helper class to do the legwork — neater than having to invoke a servlet and grab its response, etc. etc. But then what about the MVC?!?
      ;-)

      Ben Poole#
    6. Have you looked at the JSP tags in R6? They claim to do everything you've just asked for, though I haven't had the time to try them all out yet.David Truckenmiller#
    7. You've reminded me that I need to look at those too!

      Ben Poole#
    8. I think adding jsp to domino have it's value.
      the following is a salary query program i created in domino r5 servlet eviroment. everytime i get one record with too many fields, it's really a nightmare to print the html table to the browser.

      (and i also find that the servlet engine works a little abnormal.
      it seems a field can only be printed once , otherwise there will be
      a error saying "invalid column number". god ! i had to give up finally).

      but if use notes built-in agent, it seems worse.

      i do want to try jsp. with jsp, i just made the the html table in Dreamweaver or something like that, then use a jsp snippet to
      get the post data, search the database and fill the data in the
      html table.

      It 's a little nice, right?
      CODE REMOVED ON ACCOUNT OF BEING STUPIDLY LONG ;-) Zhihua#
    9. Question:
      Connection to Lotus Note by JSP

      pls: send mail for me a example JSP connect to Lotus Note:Pham Thai Phong#
    10. Um, there's code right there in the article…Ben Poole#

    Comments on this post are now closed.

    About

    I’m a software architect / developer / general IT wrangler specialising in web, mobile web and middleware using things like node.js, Java, C#, PHP, HTML5 and more.

    Best described as a simpleton, but kindly. You can read more here.

    ";