Scripting with SDO
One of the nice things about SDO is that the dynamic DataObject API provides an ideal way of passing structured data into rendering engines or JSP pages. It also enables much easier scripting of database driven web apps with ease of use to rival, if not better, scripting languages such as PHP.
Here’s an example of a JSP page to display the contents of a particular table:
|
<%@ include file="header.jsp"%> <h1>Customers</h1> <table border="1"> <tr> <td>Customer Name</td> <td>Country</td> <td>Licenses</td> </tr> <% // get a list of customer objects List list = das.getTableRows( "customer", "1=1" ); // iterate through the list Iterator iter = list.iterator(); while (iter.hasNext()) { DataObject customer = (DataObject) iter.next(); %> <tr> <td><%= customer.getString( "name") %></td> <td><%= customer.getString( "country") %></td> <td><%= customer.getString( "licenses") %></td> </tr> <% } %> </table> <%@ include file="footer.jsp"%> |
|
<% DataObject customer = (DataObject) request.getSession().getAttribute("customer"); customer.setString( "name”, request.getParameter("name") ); customer.setString( "country”, request.getParameter("country”) ); customer.setString( "licenses”, request.getParameter("licenses") ); das.applyChanges( customer ); %> |
For enterprise web applications using servlets and/or a web framework such as Struts or Spring MVC, much of this code would be encapsulated in action classes but the SDO DataObject can still be used as a convenient way of passing data to a JSP page for rendering.
Comments
Very good suggestion for implementing this DAS
Posted by: SivaKumat.T | March 29, 2006 06:18 AM