JSP Example?
Is there an example showing how to display a Grid from within a JSP? I ask because I don't see anything displayed in my JSP. If I place the script statements inside an html page it does display properly.
Jerry
May 24,
<%@ page language="java" import="java.sql.*" %>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link href="control/runtime/styles/xp/grid.css" rel="stylesheet" type="text/css" >
<script src="control/runtime/lib/grid.js"></script>
<script src="control/patches/paging1.js"></script>
<style type="text/css">
<!--
.active-controls-grid {height:80%; width:100%; font:Arial, Helvetica, sans-serif; background:background-color:#FFFFFF;}
.active-column-0 {width:40pt; text-align:center; background-color:#FFFFCC;}
.active-column-1 {width: 110pt; background-color:#CCFFFF;}
.active-column-2 {width: 60pt; text-align:center; background-color:#FFFFCC;}
.active-column-3 {width: 100pt; text-align:center; background-color:#CCFFFF;}
.active-column-4 {width: 100pt;}
.active-column-5 {width: 100pt; text-align:center; background-color:#CCFFFF;}
.active-grid-column {border-right: 1px solid black;}
.active-grid-row {border-bottom: 1px solid black;}
.active-templates-header{font-weight:bold; color:green; text-align:center;}
-->
</style>
</head>
<%
try{
Class.forName("com.mysql.jdbc.Driver");//connect driver
}
catch(ClassNotFoundException ce){
out.print(ce.getMessage());
}
%>
<body>
<%
boolean flag = false;
String datagrid = "var myData=[\n";
String sConnect = "jdbc:mysql://localhost/YourDB";//I am using MySQL database
String sUserName = ""; //you define ex: "root"
String sPassword="";//you define ex: "1234567".. ect
try{
Connection connect = DriverManager.getConnection(sConnect, sUserNam, sPassword);
ResultSet rs = null;
Statement st = connect.createStatement();
rs = st.executeQuery("SELECT * FROM YOURTABLE");
while(rs.next()){
if(!flag){
flag = true;
datagrid += "[\""+rs.getInt(1)+"\",\""+rs.getString(2)+"\",\""+rs.getString(3)+"\",\""+rs.getString(4)+"\",\""+rs.getString(5)+"\",\""+rs.getString(6)+"\"]\n";
}
else{
datagrid += ",[\""+rs.getInt(1)+"\",\""+rs.getString(2)+"\",\""+rs.getString(3)+"\",\""+rs.getString(4)+"\",\""+rs.getString(5)+"\",\""+rs.getString(6)+"\"]\n";
}
}
datagrid += "];\n";
rs.close();
st.close();
connect.close();
}
catch(SQLException se){
out.print(se.getMessage());
}
%>
<script>
var myTitle=["Column 1", "Column 2", "Column 3", "Column 4", "Column 5", "Column 6"];
<%=datagrid %>
var obj = new Active.Controls.Grid;
var row = new Active.Templates.Row; //add double click event
row.setEvent("ondblclick", function(){this.action("myAction")});
obj.setTemplate("row", row);
obj.setModel("row", new Active.Rows.Page);
obj.setColumnHeaderHeight(25);
obj.setProperty("row/count", myData.length-1);//(myData.length-1) is total rows
obj.setProperty("column/count", 6);
obj.setProperty("data/text", function(i, j){return myData[i][j]});
obj.setProperty("column/texts", myTitle);
obj.setProperty("row/pageSize", 25);
document.write(obj);
</script>
</body>
</html>
123
This topic is archived.
ActiveWidgets is a javascript library for creating user interfaces. It offers excellent performance for complex screens while staying simple, compact and easy to learn. Deployed by thousands of commercial customers in more than 70 countries worldwide.
Copyright © ActiveWidgets 2021