?
Solved

JQgrid JSP integration - data not displayed.

Posted on 2010-09-03
3
Medium Priority
?
3,170 Views
Last Modified: 2012-05-10
II am having problem in displaying data in jqGrid when I am building my XML in JSP. Grid is displayed but without any data.

Here is my JSP which connects to DB and create XML.
==============================================================================
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"_http://www.w3.org/TR/html4/loose.dtd">
<%@ page import="java.sql.*" %>
<% Class.forName("oracle.jdbc.driver.OracleDriver");  %>
<% 
	Connection connection = DriverManager .getConnection( "jdbc:oracle:thin:@localhost:test", "test", "test");
	Statement statement = connection.createStatement() ;
	ResultSet resultset = 
	statement.executeQuery("select * from mytable") ; 
%>
<%
	response.ContentType = "text/xml;charset=utf-8" 
%>
<% out.println("&lt;?xml version=\"1.0\" encoding=\"UTF-8\"?&gt;"); %>
<% 
   out.println("&lt;invoices&gt;");
   out.println("&lt;rows&gt;");
   while(resultset.next()){
	 out.println("&lt;row&gt;");
	 out.println("&lt;cell&gt;"+resultset.getString(1)+"&lt;/cell&gt;");
	 out.println("&lt;cell&gt;"+resultset.getString(2)+"&lt;/cell&gt;");
	 out.println("&lt;cell&gt;"+resultset.getString(3)+"&lt;/cell&gt;");
	 out.println("&lt;cell&gt;"+resultset.getString(4)+"&lt;/cell&gt;");
	 out.println("&lt;/row&gt;");
   } 
   out.println("&lt;/rows&gt;"); 
   out.println("&lt;/invoices&gt;");
 %>

Open in new window

]=================================================================================

Here is my other JSP which should display data in JQGrid.

==========================================================
<html>
<head>
<title>jqGrid Demo</title>
<link rel="stylesheet" type="text/css" media="screen" href="themes/basic/grid.css" />
<link rel="stylesheet" type="text/css" media="screen" href="themes/jqModal.css" />
<script src="js/jquery.js" type="text/javascript"></script>
<script src="js/jquery.jqGrid.js" type="text/javascript"></script>
<script src="js/jqModal.js" type="text/javascript"></script>
<script src="js/jqDnR.js" type="text/javascript"></script>
<script>

<%
response.ContentType = "text/xml;charset=utf-8" 
%>

jQuery(document).ready(function ()
{ jQuery("#list1").jqGrid({ 
    url:'RetrieveData.jsp',
	datatype: "xml",
	 mtype: 'POST',
    colNames:['Inv No','Date', 'Amount','Tax'],
    colModel :[ 
      {name:'invid', index:'invid', width:55, sorttype:'int'}, 
      {name:'invdate', index:'invdate', width:90, sorttype:'date', datefmt:'Y-m-d'}, 
      {name:'amount', index:'amount', width:80, align:'right', sorttype:'float'}, 
      {name:'tax', index:'tax', width:80, align:'right', sorttype:'float'}
     ],
  rowNum:10, 
  autowidth: true, 
  rowList:[10,20,30], 
  pager: jQuery('#pager1'), 
  sortname: 'id', 
  viewrecords: true, 
  sortorder: "desc", 
  caption:"XML Example" 
  }); 
}); 
</script>


</head>
<body> 
<table id="list1" class="scroll"></table> 
<div id="pager1" class="scroll" style="text-align:center;"></div> 
</body> 
</html>

Open in new window

=================================================================================

Above example works if I get the data from static XML file (i.e. - url:'RetrieveData.xml',
). Any suggestion/help would be appreciated.

Thanks
~P


0
Comment
Question by:pramathur
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
3 Comments
 
LVL 82

Accepted Solution

by:
leakim971 earned 2000 total points
ID: 33601430
you've a space before the dot here : DriverManager .getConnection
0
 
LVL 82

Expert Comment

by:leakim971
ID: 33601534
The following RetrieveData.jsp work for me :

(the JSP displaying the data in JQGrid is fine)
<%@ page contentType="text/xml" %>
<%@ page import="java.sql.*" %>
<% Class.forName("oracle.jdbc.driver.OracleDriver"); %>
<% 
	Connection connection = DriverManager.getConnection( "jdbc:oracle:thin:@localhost:test", "test", "test");	
	Statement statement = connection.createStatement();
	ResultSet resultset = statement.executeQuery("select * from test"); 
%>

<invoice>
<rows>
<% 
   while(resultset.next()) {
	 out.println("<row>");
	 out.println("<cell>" +resultset.getString(1) + "</cell>");
	 out.println("<cell>" +resultset.getString(2) + "</cell>");
	 out.println("<cell>" +resultset.getString(3) + "</cell>");
	 out.println("<cell>" +resultset.getString(4) + "</cell>");
	 out.println("</row>");
   } 
%>
</rows>
</invoice>

Open in new window

0
 
LVL 82

Expert Comment

by:leakim971
ID: 33907133
Thanks for the points!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This month, Experts Exchange’s free Course of the Month is focused on CompTIA IT Fundamentals.
The top devops trends for 2017 are focused on improved deployment frequency, decreased lead time for change and decreased MTTR.
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question