锘??xml version="1.0" encoding="utf-8" standalone="yes"?>
聽聽聽聽聽聽聽聽鏂囦歡涓婁紶鐨勫疄鐜板彲浠ラ噰鐢ㄤ笁鏂瑰寘commons-fileupload.jar錛屽叿浣撲嬌鐢ㄦ儏鍐靛彲鍙傝冿細
聽聽聽聽聽聽聽聽http://dev2dev.bea.com.cn/bbs/thread.jspa?forumID=121&threadID=8025&tstart=0&quint=true
浜屄犅犅?鏂囦歡涓?/strong>杞?br />聽聽聽聽聽聽聽聽 寰堝鏃跺欓渶瑕佷粠jsp錛堟垨xslt鐨勬煡璇㈢粨鏋滐級瀵煎嚭鍒癳xcel鎴杦ord錛屼竴涓畝鍗曠殑鏂規硶鏄噰鐢╦sp瀹炵幇錛屽叿浣撳疄鐜版柟寮忥紙浠ュ鍑哄埌excel涓轟緥錛壜犅犅犅犅犅犅?br />first.jsp(姝sp鐢ㄦ潵鏄劇ず鏌ヨ緇撴灉錛屼笂闈㈡湁涓涓寜閽紝鐐瑰嚮涓嬭澆):
<script language="javascript">
聽聽function doExport(){
聽聽聽document.all.form1.action="export.jsp";
聽聽聽聽var str = document.getElementById("table1").outerHTML;
聽聽聽document.all.excelText.value= str;
聽聽聽document.all.form1.submit();
聽聽}
<script>
聽<form name="form1" method="post" action="">
聽聽聽聽<input type="hidden" name="excelText" id="excelText" >
聽聽聽<input name="exportBtn" type="button" onclick="doExport()" class="button" value="瀵煎嚭">
</form>
聽<table width="100%" id="table1" border="1" cellpadding="2" cellspacing="1" bordercolordark="#FFFFFF">
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 .............................榪欓噷闈㈡槸鍏蜂綋闇瑕佸鍑哄幓鐨勬暟鎹?br /></table>
export.jsp(鎵ц瀵煎嚭鎿嶄綔)
<%@page contentType="text/html;charset=GB2312"%>
<%
聽String fileName="fileName";//闅忎究瀹氫箟錛屼篃鍙笉瀹氫箟
聽response.setContentType( "Application;charset=GB2312");
聽response.setHeader("Content-disposition","attachment;filename=\"" + fileName + "\";");
聽java.io.PrintWriter bos = response.getWriter();
聽String html = request.getParameter("excelText");
聽bos.write(html);
聽bos.close();
%>
鍒版錛屾枃浠跺鍑烘搷浣滃畬鎴愶紝鐐瑰嚮鈥滃鍑衡濇寜閽嵆鍙嚭鐜頒繚瀛樺璇濇銆?br />鍦ㄥ仛鐨勮繃紼嬩腑鍋剁劧紕板埌浜嗕竴涓棶棰橈紝鐐瑰嚮涓嬈″鍑猴紝鍙互欏哄埄淇濆瓨錛岀偣鍑葷浜屾鏃跺嚭鐜拌剼鏈敊璇?br />瑙e喅鏂規硶鏄湪doExport()鏂規硶涓寚瀹歞ocument.all.form1.target = "_blank";榪欐牱鍙互欏哄埄淇濆瓨錛屼絾鎵撳紑浜嗕竴涓柊紿楀彛銆?br />
鍙﹁錛?br />http://gocom.primeton.com/modules/newbb/item6387_6387.htm?PHPSESSID=954fcc1380ffdda1e535081d4c049529
聽聽
聽
1:Person.java鏂囦歡:-------------------------------
public class Person{
聽String name;
聽int age;
聽
聽public Person(String name,int age){
聽 this.name = name;
聽 this.age = age;
聽
聽}
聽public int getAge() {
聽 return age;
聽}
聽public void setAge(int age) {
聽 this.age = age;
聽}
聽public String getName() {
聽 return name;
聽}
聽public void setName(String name) {
聽 this.name = name;
聽}
}
2:Mycomparator.java-------------------------------
//瀹炵幇Comparator鎺ュ彛,涔熷氨鏄畾涔夋帓搴忚鍒?浣犲嚑涔庡彲浠ュ畾涔変換浣曡鍒?br />import java.util.*;
public class Mycomparator implements Comparator{
聽public int compare(Object o1,Object o2) {
聽 Person p1=(Person)o1;
聽 Person p2=(Person)o2;聽
聽 if(p1.age<p2.age)
聽聽 return 1;
聽 else
聽聽 return 0;
聽}
}
3:ListSort.java------------------------------------
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
public class ListSort {
聽public static void main(String[] args){
聽 ArrayList list = new ArrayList();
聽 list.add(new Person("lcl",28));
聽 list.add(new Person("fx",23));
聽 list.add(new Person("wqx",29));
聽 Comparator comp = new Mycomparator();
聽 Collections.sort(list,comp);聽
聽 for(int i = 0;i<list.size();i++){
聽聽 Person p = (Person)list.get(i);
聽聽 System.out.println(p.getName());
聽 }聽
聽
聽}
}
鍙粴鍔ㄣ佹洿鏂扮殑璁板綍闆?br />聽1銆佸垱寤哄彲婊氬姩銆佹洿鏂扮殑Statement
聽 Statement sm = cn.createStatement(ResultSet.TYPE_SCROLL_ENSITIVE,ResultSet.CONCUR_READ_ONLY);
聽 璇tatement鍙栧緱鐨凴esultSet灝辨槸鍙粴鍔ㄧ殑
聽2銆佸垱寤篜reparedStatement鏃舵寚瀹氬弬鏁?br />聽 PreparedStatemet ps = cn.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
聽 ResultSet.absolute(9000);聽
鎵歸噺鏇存柊
聽1銆丼tatement
聽 Statement sm = cn.createStatement();
聽 sm.addBatch(sql1);
聽 sm.addBatch(sql2);
聽 ...
聽 sm.executeBatch()
聽 涓涓猄tatement瀵硅薄錛屽彲浠ユ墽琛屽涓猻ql璇彞浠ュ悗錛屾壒閲忔洿鏂般傝繖澶氫釜璇彞鍙互鏄痙elete銆乽pdate銆乮nsert絳夋垨鍏兼湁
聽2銆丳reparedStatement
聽 PreparedStatement ps = cn.preparedStatement(sql);
聽 {
聽聽 ps.setXXX(1,xxx);
聽聽 ...
聽聽 ps.addBatch();
聽 }
聽 ps.executeBatch();
聽 涓涓狿reparedStatement錛屽彲浠ユ妸涓涓猻ql璇彞錛屽彉鎹㈠弬鏁板嬈℃墽琛岋紝涓嬈℃洿鏂般?/p>
聽
浜嬪姟鐨勫鐞?br />聽1銆佸叧闂瑿onnection鐨勮嚜鍔ㄦ彁浜?br />聽 cn.setAutoCommit(false);
聽2銆佹墽琛屼竴緋誨垪sql璇彞
聽 瑕佺偣錛氭墽琛屾瘡涓涓柊鐨剆ql璇彞鍓嶏紝涓婁竴嬈℃墽琛宻ql璇彞鐨凷tatement錛堟垨鑰匬reparedStatemet錛夊繀欏誨厛close
聽Statement sm ;
聽sm = cn.createStatement(insert into user...);
聽sm.executeUpdate();
聽sm.close();
聽sm = cn.createStatement("insert into corp...);
聽sm.executeUpdate();
聽sm.close();
聽3銆佹彁浜?br />聽 cn.commit();
聽4銆佸鏋滃彂鐢熷紓甯革紝閭d箞鍥炴粴
聽 cn.rollback();
Package com.first;
Public class Test1 {
聽Protected String a;
Protected void test() {
聽 System.out.println(鈥渋t is a test鈥?;
}
}
package com.second;
import com.first.*;
public class Test2 extends Test1 {
聽Test1 test1 = new Test1();
Test2 test2 = new Test2();
test1.a = 鈥渢est鈥?//閿欒
test2.a = 鈥渢est鈥? //姝g‘
test1.test();//閿欒
test2.test();//姝g‘
}
///鍘熷洜錛宲rotected瀹氫箟鐨勪笢瑗垮湪涓嶅悓鍖呭唴涓嶈兘璁塊棶錛屽彧鏈夌戶鎵跨殑瀛愮被鍙互璁塊棶
public class Test {
聽public static void main(String[] args) {
聽聽ResourceBundle rb = ResourceBundle.getBundle("test");
聽聽System.out.println(rb.getString("test"));
聽}
}