最後一篇了,感謝其他大大的支持
來介紹最近常用到的範例,為了要給Flex 呼叫的HTTP Connection
流程是Flex Builder 透過http post 把查詢資料傳給JSP,
JSP 到資料庫裡把資料依照條件組成XML 回傳給Flex 使用
最後一篇了,感謝其他大大的支持
來介紹最近常用到的範例,為了要給Flex 呼叫的HTTP Connection
流程是Flex Builder 透過http post 把查詢資料傳給JSP,
JSP 到資料庫裡把資料依照條件組成XML 回傳給Flex 使用
注意的地方是,reponse 的ContentType要設為text/xml 才可以
如果資料有中文的話,最好在CharacterEncoding也設一下
其他的看source code 看前幾篇比較一下就知道了
<%@page import="java.sql.*" %>
<%
response.setContentType("text/xml");
response.setCharacterEncoding("UTF-8");
String ptid = request.getParameter("qptid");
Connection consql = null;
try {
String url = "jdbc:jtds:sqlserver://10.10.1.119:1433/TPMANAGE";
String user = "xx";
String password = "xxxxxx";
String driver = "net.sourceforge.jtds.jdbc.Driver";
Class.forName(driver);
consql = DriverManager.getConnection(url, user, password);
Statement stmt = consql.createStatement();
String sql = "SELECT ComID,ComName,ComAddr,ContactPerson,Telephone,FaxNo,Email FROM CompanyData ";
if(ptid != null && !ptid.equals("")){
sql = sql + " WHERE PTID='"+ptid+"'";
}
System.out.println("sql:"+sql);
ResultSet rs = stmt.executeQuery(sql);
out.println("<CompanyDatas>");
while (rs.next()) {
String rscomid = rs.getString(1);
String rscomname = rs.getString(2);
String rscomaddr = rs.getString(3);
String rsconper = rs.getString(4);
String rsphone = rs.getString(5);
String rsfax = rs.getString(6);
String rsemail = rs.getString(7);
out.println(" <CompanyData>");
out.println(" <ComID>" + rscomid + "</ComID>");
out.println(" <ComName>" + rscomname + "</ComName>");
out.println(" <ComAddr>" + rscomaddr + "</ComAddr>");
out.println(" <ContactPerson>" + rsconper + "</ContactPerson>");
out.println(" <Telephone>" + rsphone + "</Telephone>");
out.println(" <FaxNo>" + rsfax + "</FaxNo>");
out.println(" <EMail>" + rsemail + "</EMail>");
out.println(" </CompanyData>");
}
out.println("</CompanyDatas>");
} catch (Exception ex) {
System.out.println(ex);
} finally {
try {
consql.commit();
consql.close();
} catch (Exception e) {
System.out.println(e);
}
}
%>