jsp產生xml檔案樣本-JSP教程,Jsp/Servlet

來源:互聯網
上載者:User
 <%@ page contenttype="text/html; charset=gb2312" %>
<%@ page language="java"%>
<%@ page info="database handler"%>
<%@ page import="java.io.*"%>
<%@ page import="java.lang.*"%>
<%@ page import="java.util.*"%>
<%@ page import="java.sql.*"%>
<%@ page import="javax.servlet.*"%>
<%@ page import="javax.servlet.http.*"%>
<html>
<head>
<meta content="text/html; charset=gb2312" http-equiv="content-type">
</head>
<body>
<%
int i=0;
string temp=null;
string parcode = request.getparameter("code");
string strsql;
try{
connection con;
statement stmt;
resultset rs;
class.forname("sun.jdbc.odbc.jdbcodbcdriver");
string url="jdbc:oracle:thin:@192.168.15.248:1521:ycdb";
con=drivermanager.getconnection(url,"webcfcquery","kill859");
//out.println("<center>jdbc串連oracle資料庫</center><br><br>");
stmt=con.createstatement();
strsql = "select account_holder,description from account_holder ";
if(parcode!=null)
strsql += " where account_holder="+ parcode +"";
rs=stmt.executequery(strsql);
fileoutputstream fo=new fileoutputstream("/usr/local/tomcat/webapps/vehicles/treasurer_voucher.xml");
printstream so = new printstream(fo);
while(rs.next()){
string col1=rs.getstring(1);
string col2=rs.getstring(2);
try{
if(i==0){
so.println("<?xml version=/"1.0/" encoding=/"gb2312/" ?>");
so.println("<ufinterface roottag=/"voucher/" billtype=/"gl/" subtype=/"/" replace=/"y/" receiver=/"1051/" sender=/"1101/" isexchange=/"y/" filename=/"會計憑證.xml/">");
so.println("<voucher id=/"1234560102/">");

// 注意:這種寫法在xml檔案顯示時會報錯,不知道為什嗎? so.println("<custcode>"+col1+"</custcode>");
so.print("<custcode>");
if(col2==null) { //如果不判斷對象col2是否為null值,那麼在進行編碼轉換時可能會出現nullpointerexception異常
so.print(col2);
} else { //因為前面已經定義xml檔案的編碼顯示方式是gb2312,所以在將字串col2寫入xml之前需轉換成gb2312,這樣在xml檔案中漢字才能正常顯示。
byte[] temp_col = col2.getbytes("gb2312");
col2 = new string(temp_col);
so.print(col2);
}
so.println("</custcode>");

}
}catch(exception e){
out.println(e.tostring());
}
i++;
}
so.println("</voucher>");
so.println("</ufinterface>");
so.close();
}catch(exception e){
out.println(e);
}
%>
</body>
</html>


文章整理:站長天空 網址:http://www.z6688.com/

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.