Søren's Blog

Random Ramblings

Previous Entry Share Next Entry
I'm getting closer and closer to some code, that I would actually recomend using.

I the previous entry I created a crude JSP Page (old fashion style). The page works, but it is ugly and alternates between code and view contexts several times (code is the scriptlets in <% ... %> and view is the HTML). These are well known problems related to all Server Pages technologies. The remidy (when using JSP) is use tag libraries instead of scriptlets (this makes it more pretty to look at), and separate the code into classes (which makes it even more pretty).

Below is a better version of the previous JSP Page. Now as a JSP Document (i.e. it's an XML document). It uses JSTL (JavaServer Pages Standard Tag Library), which means that (almost) all embedded scriptlet code is gone.

<?xml version="1.0" encoding="iso-8859-1"?>

<jsp:root xmlns:jsp="" version="1.2"

  < contentType="text/html; charset=iso-8859-1" />

  <c:set var="title" value="Database Test" />
  <c:set var="database">

  <sql:setDataSource var="connection"
    url="jdbc:hsqldb:file:${database}" driver="org.hsqldb.jdbcDriver"
    user="sa" password="" />

  <sql:query var="resultSet" dataSource="${connection}">
    SELECT title, url FROM Bookmarks ORDER BY title
      <title><c:out value="${title}" /></title>


      <h1><c:out value="${title}" /></h1>
        <c:forEach var="row" items="${resultSet.rows}">
            <c:out value="&lt;a href='${row.url}'&gt;${row.title}&lt;/a&gt;" 
               escapeXml="false" />




Log in

No account? Create an account