数据库表:tblMobile.sql 建立一个简单的测试表。
create table tblMobile (id int, name varchar(20), price decimal(10,2), image varchar(50), categoryid varchar(20)) ; insert into tblMobile(1,'hello',200,'1.jpg','moto');
这里利用一个jsp文件生成xml文件。 phonelist.jsp
<?xml version="1.0" encoding="utf-8"?>
<%@ page contentType="text/html;charset=utf-8"%>
<%@ page import="java.sql.*"%>
<phonelist>
<%
String sql = "";
String url = "";
String categoryID = request.getParameter("categoryID");
 try {


Class.forName("org.hsqldb.jdbcDriver").newInstance();
String URL="jdbc:hsqldb:hsql://localhost/xdb";
String user="sa";
String password="";
Connection conn = DriverManager.getConnection(URL,user,password);

Statement stmt = conn.createStatement();
String strOut = new String(categoryID.getBytes("ISO8859-1"), "GBK");
System.out.println("categoryID="+categoryID);
System.out.println("categoryID="+strOut);
sql = "select id, name, price, image from tblMobile where categoryid='" + strOut + "'";
ResultSet rs = stmt.executeQuery(sql);
 while (rs.next()) {
out.println("<phone id=\"" + rs.getString(1) + "\">");
out.println("<id>" + rs.getString(1) + "</id>");
out.println("<name>" + rs.getString(2) + "</name>");
out.println("<price>" + rs.getString(3) + "</price>");
out.println("<image>" + rs.getString(4) + "</image>");
out.println("</phone>");
}
rs.close();
stmt.close();
conn.close();
 } catch (Exception e) {
out.println(e);
}
%>
</phonelist>

test.lzx
<canvas height="100" width="500" >
<dataset name="myData" autorequest="true" type="http" src="phonelist.jsp?categoryID=moto"/>

<simplelayout axis="y"/>

<view datapath="myData:/phonelist/phone">
<simplelayout axis="x"/>
<text datapath="image/text()" />
<text datapath="name/text()" />
</view>

</canvas>

|