5426l3 Listing 3: WelcomePresentation.java, the Java Class that Displays Our HTML with Input from the Database /* * blog * * Enhydra super-servlet presentation object * */ package il.co.lerner.presentation; // Enhydra SuperServlet imports import com.lutris.appserver.server.httpPresentation.HttpPresentation; import com.lutris.appserver.server.httpPresentation.HttpPresentationComms; import com.lutris.appserver.server.httpPresentation.HttpPresentationException; // The following two lines import our specific data objects import blog.*; import com.lutris.dods.builder.generator.query.*; // We will use a Vector to build our query import java.util.Vector; // Standard imports import java.io.IOException; import java.util.Date; import java.text.DateFormat; public class WelcomePresentation implements HttpPresentation { public void run(HttpPresentationComms comms) throws HttpPresentationException, IOException, NonUniqueQueryException, DataObjectException, QueryException { // Get the HTML from the Welcome page as an object WelcomeHTML welcome = (WelcomeHTML)comms.xmlcFactory.create(WelcomeHTML.class); // Create a new query object BlogEntriesQuery blogq = new BlogEntriesQuery(); // Retrieve entries that came before now -- this lets us write // blog entries with future dates, which comes on-line // automatically at a certain point blogq.setQueryEntrydate("NOW()", QueryBuilder.LESS_THAN); // Indicate that we want DESC order blogq.addOrderByEntrydate(false); // Execute our query, returning an array of blog entries BlogEntriesDO[] blogEntries = blogq.getDOArray(); // Put the first text and date entries in the text welcome.setTextDate(blogEntries[0].getEntrydate()); welcome.setTextText(blogEntries[0].getText()); // Send the HTML back to the user's browser comms.response.writeDOM(welcome); } }