Categories | Question details Back To List | ||
Error in SmartRendering i am using SmartRendering with "sample of server side code. JSP" in tutorial and my database connectparametern. The lines of code is: <link rel="STYLESHEET" type="text/css" href="dhtmlxgrid.css"> <script src="dhtmlxcommon.js"></script> <script src="dhtmlxgrid.js"></script> <script src="dhtmlxgridcell.js"></script> <script src="ext/dhtmlxgrid_srnd.js"></script> <script> 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 Answer posted by Support on Jul 07, 2008 07:12 >>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 http://dhtmlx.com/docs/products/dhtmlxGrid/doc/articles/Common_Problems_in_Grid.html#grid_art_comprob http://dhtmlx.com/docs/products/kb/index.shtml?cat=search&q=2545&ssr=yes&s=dhtmlxcommon Answer posted by pyt on Jul 07, 2008 08:05 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("<rows total_count='" + totalCount + "' pos='" + posStart + "'>"); while (rs.next()) { out.println("<row id='" + rs.getString("DEPARTMENT_ID") + "'>"); out.println("<cell>"); out.println(rs.getString("DEPARTMENT_NAME")); // value for product name out.println("</cell>"); out.println("<cell>"); out.println(rs.getString("MANAGER_ID")); // value for internal code out.println("</cell>"); out.println("<cell>"); out.println(rs.getString("LOCATION_ID")); // value for price out.println("</cell>"); out.println("</row>"); } out.write("</rows>"); rs.close(); %> is it all i need? i mean no xml file or WEB-INF? thanks Answer posted by Support on Jul 07, 2008 10:04 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. |