<%@ page import="com.kesoftware.imu.*" %> <% /* * Create new session object. */ Session imuSession = new Session(); imuSession.setHost("imu.mel.kesoftware.com"); /* * Work out what port to connect to. */ int port = 40136; if (request.getParameter("port") != null) port = Integer.parseInt(request.getParameter("port")); imuSession.setPort(port); // example-2 /* * Establish connection and tell the server we may want to re-connect. */ imuSession.connect(); imuSession.setSuspend(true); // example-3 /* * Create module object and tell the server not to destroy it. */ Module module = new Module("eparties", imuSession); module.setDestroy(false); // example-4 /* If name is supplied, do new search. The search term is passed from * example.html using GET. */ if (request.getParameter("name") != null) { Terms terms = new Terms(TermsKind.OR); terms.add("NamLast", request.getParameter("name")); module.findTerms(terms); } /* * Otherwise, if id is supplied reattach to existing server-side object. */ else if (request.getParameter("id") != null) { module.setID(request.getParameter("id")); } /* * Otherwise, we can't process. */ else { throw new Exception("no name or id"); } // example-5 String[] columns = { "NamFirst", "NamLast" }; // example-6 /* * Work out which block of records to fetch. */ int rownum = 1; if (request.getParameter("rownum") != null) rownum = Integer.parseInt(request.getParameter("rownum")); // example-7 /* * Fetch next five records */ ModuleFetchResult result = module.fetch("start", (rownum - 1), 5, columns); long hits = result.getHits(); /* * Save rows in convenient variable for later use. */ Map[] rows = result.getRows(); /* * Build the results page */ %> IMu JAVA API - Maintaining State

Number of matches: <% out.print(hits); %>

<% // Display each match in a separate row in a table for (int i = 0; i < rows.length; i++) { Map row = rows[i]; Long num = row.getLong("rownum"); out.println(""); out.println("\t"); out.println("\t
" + num.toString() + "" + row.getString("NamFirst") + " " + row.getString("NamLast") + ""); } %>
<% // example-8 /* * Add the Prev and Next links */ String url = request.getRequestURL().toString(); url += "?port=" + imuSession.getPort(); url += "&id=" + module.getID(); // example-9 Map first = rows[0]; if (first.getLong("rownum") > 1) { Long prev = (first.getLong("rownum") - 5); if (prev < 1L) prev = 1L; out.println("Prev"); } Map last = rows[rows.length - 1]; if (last.getLong("rownum") < hits) { Long next = last.getLong("rownum") + 1L; out.println("Next"); } %>