tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Edward & Iona Brode" <edward-i...@brode.co.uk>
Subject JSP written in XML
Date Sat, 18 May 2002 09:28:12 GMT
Hi All,

I seem to be having trouble with the parser in Jasper.
I'm trying to write a jsp page in xml, that is, using
such syntax as <jsp:scriptlet></jsp:scriptlet>.

The problem is that some of the code is being placed into
the out.write statements in the generated servlet.

Here's the jsp:
<?xml version="1.0"?>
<!-- coffees_xml.jsp -->
<jsp:root xmlns:jsp="http://java.sun.com/products/jsp/dtd/jsp_1_0.dtd">
 <jsp:directive.page content="text/html"/>
  <jsp:directive.page import="java.sql.*" />
  <jsp:directive.page import="java.sql.Connection" />
  <jsp:directive.page import="java.sql.Statement" />
  <jsp:directive.page import="java.sql.ResultSet" />
  <jsp:directive.page import="java.sql.SQLException" />
  <jsp:scriptlet>
   out.write("<html><title>Cafe Java</title><head></head><body><h1>Welcome
to Cafe Java!</h1><h2>Available
Coffees:</h2><table><tr><th>Coffee</th><th>Price</th></tr>");
  Connection conn = null;
  Statement stmt = null;
  ResultSet rs = null;
  String url = "jdbc:odbc:CafeJava";
  String query = "select COF_NAME, PRICE from COFFEES";
  try {
   Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

  }
  catch(java.lang.ClassNotFoundException e) {
   System.err.print("ClassNotFoundException: " + e.getMessage());
  }
  try {
   conn = DriverManager.getConnection(url, "Admin", "duke1");

   stmt = conn.createStatement();
   rs = stmt.executeQuery(query);
   while (rs.next()) {
    String s = rs.getString("COF_NAME");
    float f = rs.getFloat("PRICE");
        out.write("<tr><td>" + s + "</td><td>" + f + "</td></tr>");
      }

   stmt.close();
   conn.close();

  } catch(SQLException ex) {
   System.err.println("SQLException: " + ex.getMessage());
  }
   out.write("</table></body></html>");
 </jsp:scriptlet>
</jsp:root>

The resulting html looks like this:

<html ><title >Cafe Java</title><head ></head><body ><h1
>Welcome to Cafe
Java!</h1><h2 >Available Coffees:</h2><table ><tr ><th >Coffee</th><th
>Price</th></tr>");
  Connection conn = null;
  Statement stmt = null;
  ResultSet rs = null;
  String url = "jdbc:odbc:CafeJava";
  String query = "select COF_NAME, PRICE from COFFEES";
  try {
   Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

  }
  catch(java.lang.ClassNotFoundException e) {
   System.err.print("ClassNotFoundException: " + e.getMessage());
  }
  try {
   conn = DriverManager.getConnection(url, "Admin", "duke1");

   stmt = conn.createStatement();
   rs = stmt.executeQuery(query);
   while (rs.next()) {
    String s = rs.getString("COF_NAME");
    float f = rs.getFloat("PRICE");
        out.write("<tr ><td >" + s + "</td><td >" + f + "</td></tr>");
      }

   stmt.close();
   conn.close();

  } catch(SQLException ex) {
   System.err.println("SQLException: " + ex.getMessage());
  }
   out.write("</table></body></html>

 Any ideas, suggestions?

 Thanks,

 Edward Brode




--
To unsubscribe, e-mail:   <mailto:tomcat-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:tomcat-user-help@jakarta.apache.org>


Mime
View raw message