java生成异地xml?
用java写了一个webservice,里面有个方法:从数据库中读取数据然后生成一个xml文件。
现在要从别的机子上调用这个webservice里的方法,但是最后却在我的机子上生成了xml,怎么回事?
需要怎么改?
代码:
package com.accp.Impl;
import java.io.FileOutputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.output.Format;
import org.jdom.output.XMLOutputter;
import com.accp.Inter.getxmlTest;
import com.travelsky.ibe.client.FD;
import com.travelsky.ibe.client.FDResult;
public class getxml implements getxmlTest {
public Connection con;
protected boolean connected = false;
public void connect()
{
try{
if(connected)
return;
else {
/*Context ctx = new InitialContext();
DataSource ds = (DataSource)ctx.lookup("java:comp/env/jdbc/HBCCT");
con = ds.getConnection();*/
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
String url= "jdbc:sqlserver://10.7.144.5:1433;databasename=exploitDebug;user=webuser;password=5p6182oebq61";
con = DriverManager.getConnection(url);
System.out.println("ok...");
}
}catch(Exception e){
System.out.println("SAS:/> Err DbConn.connect(): "+e);
}
}
public void getXML(String a,String b,String c,String d,String url){
try {
String Price_Y = "";
String Type_fd = "";
Timedefine timedefine = new Timedefine();
//FD方法与IBE的连接
FD fd=new FD();
FDResult fdResult= new FDResult();
fdResult = fd.findPrice(a.substring(0,3),b.substring(0,3),timedefine.showMMM(c),d);
System.out.println(fdResult);
Element employees,emp,ename,job;
employees = new Element("机票信息");
Document doc = new Document(employees);
if(fdResult.getElementNum()>0)
{
for(int j=0;j<fdResult.getElementNum();j++)
{
/*System.out.println("第"+j+"个");
String zhekou = fdResult.getDiscountRate(j);
System.out.println("仓位:"+fdResult.getCabinType(j));
System.out.println("折扣率:"+zhekou);
Price_Y = fdResult.getSinglePrice(j);//获取单程票价
System.out.println(Price_Y);
Type_fd = fdResult.getCabinType(j);//获取仓位类型
if(Type_fd.equals("Y"))
break;*/
emp = new Element("机票");
doc.getRootElement().addContent(emp);
ename = new Element("仓位");
ename.setText(fdResult.getCabinType(j));
emp.addContent(ename);
job = new Element("折扣率");
job.setText(fdResult.getDiscountRate(j));
emp.addContent(job);
}
}
XMLOutputter outp = new XMLOutputter(Format.getCompactFormat());
Format format = outp.getFormat();
format.setEncoding("GB2312");
format.setExpandEmptyElements(true);
outp.setFormat(format);
outp.output(doc,new FileOutputStream(url));
}
catch (Exception e)
{
}
}
public static void main(String[] args){
getxml gg = new getxml();
gg.getXML("CTU", "KWE", "2009-06-01", "G5","d:/b.xml");
}
}
高手赶紧帮忙,我着急用呢
[解决办法]
你应该用WS来传递XML数据,然后用接收的XML生成文件,而不是直接在WS中生成XML。