problem in binding xml file data to datagrid xml file is generated through JSP file

problem in binding xml file data to datagrid xml file is generated through JSP file

Post by cksha » Fri, 27 May 2005 22:12:39


problem it that i am creating xml file using JSP file and i want to bind
DataGrid with xml file data that is created using JSP
but it will not Bind

two basic err occcur jsp file when i compiling MXML file

1) <xml> the xml tag only appear as first text in the file
2) problem parsing external xml

i need proper solution both file code are as under
*******************************JSP
file************************************************

<%@ page contentType="text/html; charset=iso-8859-1" language="java"
import="java.sql.*" errorPage="" %>
<?xml version="1.0" encoding="iso-8859-1"?>
<employees>
<%
Connection conn=null;
try
{
String driverName="org.gjt.mm.mysql.Driver";
Class.forName(driverName);

String url="jdbc:mysql://192.168.1.149/flextest";
String username="root";
String password="vamsi";
conn=DriverManager.getConnection(url,username,password);
out.println("Connection...");
String query="Select * from temp";
Statement stmt=conn.createStatement();
ResultSet rs=stmt.executeQuery(query);
while(rs.next())
{
%>
<employee>
<id> <% out.println(rs.getString(1)); %> </id>
<phone> <% out.println(rs.getString(2)); %> </phone>
<email> <% out.println(rs.getString(3)); %> </email>
</employee>

<%
}

}
catch (ClassNotFoundException cle)
{
System.out.println("ClassNotFoudException :"+cle);
} catch (SQLException e)
{
System.out.println("ClassNotFoudException :"+e);
// Could not connect to the database
}
%>
</employees>


*********************************************MXMLFILE***************************
**********************************
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.macromedia.com/2003/mxml">

<mx:HTTPService id="employeeSrv" useProxy="false" method="POST"
url="http://localhost:8888/samples/chinmay/emp.jsp" >
<mx:request>
<id>{name.text}</id>
<phone>{phone.text}</phone>
<email>{email.text}</email>
</mx:request>
</mx:HTTPService>

<mx:Script>
function addRow() {
if (name.text != "") dg.addItem( {id: name.text, email:
email.text, phone: phone.text} );
employeeSrv.send();

}

function updateRow() {
if (dg.selectedIndex!=undefined)
dg.replaceItemAt(dg.selectedIndex, {id: name.text, email:
email.text, phone: phone.text} );
}

function deleteRow() {
if (dg.selectedIndex!=undefined) {
dg.removeItemAt(dg.selectedIndex);
name.text=""; email.text=""; phone.text="";
}
}
</mx:Script>
<mx:Model id="empdata"
source="http://localhost:8888/samples/chinmay/emp.jsp"/>
<mx:Panel xmlns:mx="http://www.macromedia.com/2003/mxml" width="400"
height="419">
<mx:VBox>
<mx:DataGrid id="dg" dataProvider="{empdata.employee}">
<mx:columns>
<mx:Array>
<mx:DataGridColumn headerText="id" columnName="id" />
<mx:DataGridColumn headerText="phone" columnName="phone" />
<mx:Data
 
 
 

problem in binding xml file data to datagrid xml file is generated through JSP file

Post by ntsii » Sat, 28 May 2005 00:54:16

Cal the JSP form a browser. You will either get good xml, or you will see an error that will help you debug.

Tracy

 
 
 

problem in binding xml file data to datagrid xml file is generated through JSP file

Post by ntsii » Sat, 28 May 2005 00:55:32

Also, put this at the top of the jsp file:
response.setContentType("text/xml");