jsp產生xml檔案樣本

來源:互聯網
上載者: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>
相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.