zhaoling
05-20-2007, 11:42 PM
I try to use the code as follows to implement conmunication between the Lzx application and jsp,but just can't get the value of the parameters in the jsp.
------code of the lzx:
<?xml version="1.0" encoding="UTF-8" ?>
<canvas debug="true">
<debug/>
<dataset name="res" src="resxml.jsp" type="http" request="false"
ondata="Debug.write(this.data)"/>
<class name="test" extends="view">
<method name="dirSelected">
var d=canvas.datasets.res;
var t=new LzParam();
t.setValue("dirID","d001" , true);
t.setValue("snode","tr", true);
d.setQueryString(t);
Debug.write("'"+d.getQueryString()+"'");
d.doRequest();
</method>
</class>
<view>
<test name="newtest">
<button>
<handler name="onclick">
parent.dirSelected();
</handler>
</button>
</test>
</view>
</canvas>
-------code of jsp page:
<%@ page contentType="text/xml; charset=UTF-8" language="java" import="java.sql.*" errorPage="" %>
<%@ page import="com.ibm.db2.jcc.DB2Driver"%>
<%@ page import="java.io.*"%>
<%@page import="java.util.*"%>
<%//out.write("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n");%>
<infolist>
<%String drName="com.ibm.db2.jcc.DB2Driver";
String uName="db2admin";
String upwd="123";
String url="jdbc:db2:resinfo";
String sql1="";
String sql2="";
Connection con=null;
Statement stm=null;
ResultSet rs=null;
//connect to database
try{
Class.forName(drName);
con=DriverManager.getConnection(url,uName,upwd);
stm=con.createStatement();
String dirID=request.getParameter("dirID");
String snode=request.getParameter("snode");
out.println(dirID);
out.println(snode);
sql1="select * from ADMINISTRATOR.INFO where DIRID='"+dirID+"'";
sql2="select * from ADMINISTRATOR.INFO where SUBDIRID='"+dirID+"'";
if (snode == null)
out.println("snode is null");
if(snode!=null){
if(snode.equals("fa"))
{
rs=stm.executeQuery(sql1);
while(rs.next()){
out.println(rs.getString("DETAILXML"));
}
}
if(snode.equals("tr"))
{
rs=stm.executeQuery(sql2);
while(rs.next()){
out.println(rs.getString("DETAILXML"));
}
}
}
}catch(SQLException sqle){
sqle.printStackTrace();
}
finally {
System.out.println("executing finally ");
try {
System.out.println("Closing the statement and connection");
if(null!=rs){
rs.close();
}
if(null != stm){
stm.close();
}
con.close();
System.out.println("closing the connection");
} catch (Exception e) {
System.out.println("There is exception in the finally block");
e.printStackTrace();
}
}
%>
</infolist>
-----------------------------------------
the result in the Lzx page:(through debug)
'snode=tr&dirID=d001'
«ˇLzDataElement!#0| <infolist>\r\n d001\r\ntr\r\n\r\n\t\t\t\r\n</infolist>»
-----------------------------------------
the result in the jsp page:
<infolist>null null snode is null</infolist>
------code of the lzx:
<?xml version="1.0" encoding="UTF-8" ?>
<canvas debug="true">
<debug/>
<dataset name="res" src="resxml.jsp" type="http" request="false"
ondata="Debug.write(this.data)"/>
<class name="test" extends="view">
<method name="dirSelected">
var d=canvas.datasets.res;
var t=new LzParam();
t.setValue("dirID","d001" , true);
t.setValue("snode","tr", true);
d.setQueryString(t);
Debug.write("'"+d.getQueryString()+"'");
d.doRequest();
</method>
</class>
<view>
<test name="newtest">
<button>
<handler name="onclick">
parent.dirSelected();
</handler>
</button>
</test>
</view>
</canvas>
-------code of jsp page:
<%@ page contentType="text/xml; charset=UTF-8" language="java" import="java.sql.*" errorPage="" %>
<%@ page import="com.ibm.db2.jcc.DB2Driver"%>
<%@ page import="java.io.*"%>
<%@page import="java.util.*"%>
<%//out.write("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n");%>
<infolist>
<%String drName="com.ibm.db2.jcc.DB2Driver";
String uName="db2admin";
String upwd="123";
String url="jdbc:db2:resinfo";
String sql1="";
String sql2="";
Connection con=null;
Statement stm=null;
ResultSet rs=null;
//connect to database
try{
Class.forName(drName);
con=DriverManager.getConnection(url,uName,upwd);
stm=con.createStatement();
String dirID=request.getParameter("dirID");
String snode=request.getParameter("snode");
out.println(dirID);
out.println(snode);
sql1="select * from ADMINISTRATOR.INFO where DIRID='"+dirID+"'";
sql2="select * from ADMINISTRATOR.INFO where SUBDIRID='"+dirID+"'";
if (snode == null)
out.println("snode is null");
if(snode!=null){
if(snode.equals("fa"))
{
rs=stm.executeQuery(sql1);
while(rs.next()){
out.println(rs.getString("DETAILXML"));
}
}
if(snode.equals("tr"))
{
rs=stm.executeQuery(sql2);
while(rs.next()){
out.println(rs.getString("DETAILXML"));
}
}
}
}catch(SQLException sqle){
sqle.printStackTrace();
}
finally {
System.out.println("executing finally ");
try {
System.out.println("Closing the statement and connection");
if(null!=rs){
rs.close();
}
if(null != stm){
stm.close();
}
con.close();
System.out.println("closing the connection");
} catch (Exception e) {
System.out.println("There is exception in the finally block");
e.printStackTrace();
}
}
%>
</infolist>
-----------------------------------------
the result in the Lzx page:(through debug)
'snode=tr&dirID=d001'
«ˇLzDataElement!#0| <infolist>\r\n d001\r\ntr\r\n\r\n\t\t\t\r\n</infolist>»
-----------------------------------------
the result in the jsp page:
<infolist>null null snode is null</infolist>