i am using SmartRendering with “sample of server side code. JSP” in tutorial and my database connectparametern.
The lines of code is:
var mygrid;
function doInitGrid(){
mygrid = new dhtmlXGridObject(‘mygrid_container’);
mygrid.setImagePath(“codebase/imgs/”);
mygrid.setHeader(“Model,Qty,Price”);
mygrid.setInitWidths("*,150,150");
mygrid.setColAlign(“left,right,right”)
mygrid.setSkin(“light”);
mygrid.setColSorting(“str,int,int”);
mygrid.setColTypes(“ed,ed,ed”);
mygrid.init();
mygrid.enableSmartRendering(true);
gridQString = “getGridRecords.jsp”;
mygrid.loadXML(gridQString );
}
but i can’t load the file from database. Error: incorrect XML
but i can’t load the file from database. Error: incorrect XML
Such error occurs when server side code generates incorrect XML
You can try to use debug version of dhtmlxcommon, which will show exact called url and server side response
dhtmlx.com/docs/products/kb/inde … tmlxcommon
but all i have, is a jsp file. The lines of code is:
<%@ page language=“java” contentType=“text/html; charset=ISO-8859-1”
pageEncoding=“ISO-8859-1”%>
<%@ page import = “java.sql." %>
<%
String db_ipp_addr = “invidia”;
String db_username = “hr”;
String db_password = “hr”;
String db_name = “XE”;
// set content type and xml tag
response.setContentType(“text/xml”);
out.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
// define variables from incoming values
String posStart = “”;
if (request.getParameter(“posStart”) != null){
posStart = request.getParameter(“posStart”);
}else{
posStart = “0”;
}
String count = “”;
if (request.getParameter(“count”) != null){
count = request.getParameter(“count”);
}else{
count = “100”;
}
// connect to database
Connection connection = null;
Statement statement = null;
ResultSet rs = null;
String connectionURL = “jdbc:oracle:thin:@invidia:1521:XE” ;
Class.forName(“oracle.jdbc.driver.OracleDriver”).newInstance();
connection = DriverManager.getConnection(connectionURL, db_username, db_password);
// query to products table
String sql = “SELECT * FROM Departments”;
// if this is the first query - get total number of records in the query result
String totalCount = “”;
if (posStart.equals(“0”)){
String sqlCount = "Select count() as cnt from (” + sql + “) as tbl”;
statement = connection.createStatement();
rs = statement.executeQuery(sqlCount);
rs.next();
totalCount = rs.getString(“cnt”);
rs.close();
} else {
totalCount = “”;
}
// add limits to query to get only rows necessary for output
sql += " LIMIT " + posStart + “,” + count;
// Execute the query
statement = connection.createStatement();
rs = statement.executeQuery(sql);
// output data in XML format
out.println("");
while (rs.next()) {
out.println("");
out.println("");
out.println(rs.getString(“DEPARTMENT_NAME”)); // value for product name
out.println("");
out.println("");
out.println(rs.getString(“MANAGER_ID”)); // value for internal code
out.println("");
out.println("");
out.println(rs.getString(“LOCATION_ID”)); // value for price
out.println("");
out.println("");
}
out.write("");
rs.close();
%>
is it all i need? i mean no xml file or WEB-INF?
thanks
There is a line, which can cause problem
You have next statement, which mark output encoding
<%@ page language=“java” contentType=“text/html; charset=ISO-8859-1”
pageEncoding=“ISO-8859-1”%>
but in same time you have different encoding in xml header
out.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
both places must use the same encoding ( one which really used for data storing )
>>s it all i need? i mean no xml file or WEB-INF?
From client-side code perspective all other looks fine. The client side code must receive XML with correct structure and encoding, all other doesn’t matter.