Ajax+Flash多文件上傳是一個開源的上傳組件,名稱是FancyUpload,其官方網址是:http://digitarald.de/project/fancyupload/。這個組件僅僅是客戶端的應用組件,即與任何服務器端的技術沒有關系,服務器端可以采用任何后臺技術(如JSP、Servlet、ASP等)。應用該組件提供
給我們的最大的好處有如下幾點(個人認為,呵呵):
2 可以同時選擇多個文件進行上傳;
3 以隊列的形式排列要上傳的文件和其相關信息(如名稱、大小等);
4 可以設置要上傳的文件個數、文件類型和文件大小;
5 有上傳進度顯示, 直觀,實用);
6 上傳的過程中可以隨時取消要上傳的文件;
7 平臺獨立性,由于使用flash和 成熟的AJAX框架(mootools)可以避免對特定瀏覽器和服務器依賴!
8 使用簡單,文件體積小!
9 表單無須設置enctype="multipart/form-data"
<html>
<head>
<title>Add Files</title>
<style>
a.addfile {
background-image:url(http://p.mail.163.com/js31style/lib/0703131650/163blue/f1.gif);
background-repeat:no-repeat;
background-position:-823px -17px;
display:block;
float:left;
height:20px;
margin-top:-1px;
position:relative;
text-decoration:none;
top:0pt;
width:80px;
}
input.addfile {
/*left:-18px;*/
}
input.addfile {
cursor:pointer !important;
height:18px;
left:-13px;
filter:alpha(opacity=0);
position:absolute;
top:5px;
width:1px;
z-index: -1;
}
</style>
<script type="text/javascript">
function MultiSelector(list_target, max)
{
// Where to write the list
this.list_target = list_target;
// How many elements?
this.count = 0;
// How many elements?
this.id = 0;
// Is there a maximum?
if (max)
{
this.max = max;
}
else
{
this.max = -1;
};
/**
* Add a new file input element
*/
this.addElement = function(element)
{
// Make sure it's a file input element
if (element.tagName == 'INPUT' && element.type == 'file')
{
// Element name -- what number am I?
element.name = 'file_' + this.id++;
// Add reference to this object
element.multi_selector = this;
// What to do when a file is selected
element.onchange = function()
{
// New file input
var new_element = document.createElement('input');
new_element.type = 'file';
new_element.size = 1;
new_element.className = "addfile";
// Add new element
this.parentNode.insertBefore(new_element, this);
// Apply 'update' to element
this.multi_selector.addElement(new_element);
// Update list
this.multi_selector.addListRow(this);
// Hide this: we can't use display:none because Safari doesn't like it
this.style.position = 'absolute';
this.style.left = '-1000px';
};
// If we've reached maximum number, disable input element
if (this.max != -1 && this.count >= this.max)
{
element.disabled = true;
};
// File element counter
this.count++;
// Most recent element
this.current_element = element;
}
else
{
// This can only be applied to file input elements!
alert('Error: not a file input element');
};
};
/**
* Add a new row to the list of files
*/
this.addListRow = function(element)
{
// Row div
var new_row = document.createElement('div');
// Delete button
var new_row_button = document.createElement('input');
new_row_button.type = 'button';
new_row_button.value = 'Delete';
// References
new_row.element = element;
// Delete function
new_row_button.onclick = function()
{
// Remove element from form
this.parentNode.element.parentNode.removeChild(this.parentNode.element);
// Remove this row from the list
this.parentNode.parentNode.removeChild(this.parentNode);
// Decrement counter
this.parentNode.element.multi_selector.count--;
// Re-enable input element (if it's disabled)
this.parentNode.element.multi_selector.current_element.disabled = false;
// Appease Safari
// without it Safari wants to reload the browser window
// which nixes your already queued uploads
return false;
};
// Set row value
new_row.innerHTML = element.value + " ";
// Add button
new_row.appendChild(new_row_button);
// Add it to the list
this.list_target.appendChild(new_row);
};
};
</script>
</head>
<body>
<!-- This is the form -->
<form enctype="multipart/form-data" action="http://127.0.0.1:8080/zzgh/cx/upload.jsp" method="post">
<!-- The file element -- NOTE: it has an ID -->
<a href="javascript:void(1==1);" class="addfile" style="cursor: default;" hidefocus="true">
<input id="my_file_element" class="addfile" type="file" name="file_1" size="1" title="點擊選擇附件">
</a>
<input type="submit" value="上 傳">
</form>
Files:
<!-- This is where the output will appear -->
<div id="files_list" style="padding:5px;border:1px;border-style:solid;border-color:#0000ff;height:100px;width:600px;"></div>
<script>
<!-- Create an instance of the multiSelector class, pass it the output target and the max number of files -->
var multi_selector = new MultiSelector(document.getElementById('files_list'), 100);
<!-- Pass in the file element -->
multi_selector.addElement(document.getElementById('my_file_element'));
</script>
</body>
</html>
效果圖如下:

一,先新建一個excel文件,調整格式(就是你所想要顯示的格式),
二,把剛才新建的excel文件令存為.html(demo.html)文件,
三,新建一個jsp頁面, 在該JSP頁面頭部設置response的ContentType為Excel格式
<% response.setContentType("application/vnd.ms-excel;charset=GBK"); %>
然后設置網頁資料是以excel報表以線上瀏覽方式呈現或者是下載的方式呈現
<%
/ /這行設定傳送到前端瀏覽器時的檔名為test1.xls 就是靠這一行,讓前端瀏覽器以為接收到一個excel檔
//將網頁資料以excel報表以線上瀏覽方式呈現
response.setHeader("Content-disposition","inline; filename=test1.xls");
//將網頁資料以下載的方式
response.setHeader("Content-disposition","attachment; filename=test2.xls");
%>
然后把 demo.html的源代碼粘貼在jsp頁面,如下
<%@ page contentType="text/html; charset=GBK" %>
<% response.setContentType("application/vnd.ms-excel;charset=GBK");
response.setHeader("Content-disposition","attachment; filename=test2.xls");
%>
<!--以下為保持成html頁面的excel的內容 demo.html頁面-->
<html xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:x="urn:schemas-microsoft-com:office:excel"
xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv=Content-Type content="text/html; charset=gb2312">
<meta name=ProgId content=Excel.Sheet>
<meta name=Generator content="Microsoft Excel 11">
<link rel=File-List href="qwe.files/filelist.xml">
<link rel=Edit-Time-Data href="qwe.files/editdata.mso">
<link rel=OLE-Object-Data href="qwe.files/oledata.mso">
<!--[if gte mso 9]><xml>
<o:DocumentProperties>
<o:Created>1996-12-17T01:32:42Z</o:Created>
<o:LastSaved>2010-05-12T13:59:04Z</o:LastSaved>
<o:Version>11.9999</o:Version>
</o:DocumentProperties>
<o:OfficeDocumentSettings>
<o:RemovePersonalInformation/>
</o:OfficeDocumentSettings>
</xml><![endif]-->
<style>
<!--table
{mso-displayed-decimal-separator:"\.";
mso-displayed-thousand-separator:"\,";}
@page
{margin:1.0in .75in 1.0in .75in;
mso-header-margin:.5in;
mso-footer-margin:.5in;}
tr
{mso-height-source:auto;
mso-ruby-visibility:none;}
col
{mso-width-source:auto;
mso-ruby-visibility:none;}
br
{mso-data-placement:same-cell;}
.style0
{mso-number-format:General;
text-align:general;
vertical-align:bottom;
white-space:nowrap;
mso-rotate:0;
mso-background-source:auto;
mso-pattern:auto;
color:windowtext;
font-size:12.0pt;
font-weight:400;
font-style:normal;
text-decoration:none;
font-family:宋體;
mso-generic-font-family:auto;
mso-font-charset:134;
border:none;
mso-protection:locked visible;
mso-style-name:常規;
mso-style-id:0;}
td
{mso-style-parent:style0;
padding-top:1px;
padding-right:1px;
padding-left:1px;
mso-ignore:padding;
color:windowtext;
font-size:12.0pt;
font-weight:400;
font-style:normal;
text-decoration:none;
font-family:宋體;
mso-generic-font-family:auto;
mso-font-charset:134;
mso-number-format:General;
text-align:general;
vertical-align:bottom;
border:none;
mso-background-source:auto;
mso-pattern:auto;
mso-protection:locked visible;
white-space:nowrap;
mso-rotate:0;}
ruby
{ruby-align:left;}
rt
{color:windowtext;
font-size:9.0pt;
font-weight:400;
font-style:normal;
text-decoration:none;
font-family:宋體;
mso-generic-font-family:auto;
mso-font-charset:134;
mso-char-type:none;
display:none;}
-->
</style>
<!--[if gte mso 9]><xml>
<x:ExcelWorkbook>
<x:ExcelWorksheets>
<x:ExcelWorksheet>
<x:Name>Sheet1</x:Name>
<x:WorksheetOptions>
<x:DefaultRowHeight>285</x:DefaultRowHeight>
<x:CodeName>Sheet1</x:CodeName>
<x:Selected/>
<x:Panes>
<x:Pane>
<x:Number>3</x:Number>
<x:ActiveCol>1</x:ActiveCol>
</x:Pane>
</x:Panes>
<x:ProtectContents>False</x:ProtectContents>
<x:ProtectObjects>False</x:ProtectObjects>
<x:ProtectScenarios>False</x:ProtectScenarios>
</x:WorksheetOptions>
</x:ExcelWorksheet>
<x:ExcelWorksheet>
<x:Name>Sheet2</x:Name>
<x:WorksheetOptions>
<x:DefaultRowHeight>285</x:DefaultRowHeight>
<x:CodeName>Sheet2</x:CodeName>
<x:ProtectContents>False</x:ProtectContents>
<x:ProtectObjects>False</x:ProtectObjects>
<x:ProtectScenarios>False</x:ProtectScenarios>
</x:WorksheetOptions>
</x:ExcelWorksheet>
<x:ExcelWorksheet>
<x:Name>Sheet3</x:Name>
<x:WorksheetOptions>
<x:DefaultRowHeight>285</x:DefaultRowHeight>
<x:CodeName>Sheet3</x:CodeName>
<x:ProtectContents>False</x:ProtectContents>
<x:ProtectObjects>False</x:ProtectObjects>
<x:ProtectScenarios>False</x:ProtectScenarios>
</x:WorksheetOptions>
</x:ExcelWorksheet>
</x:ExcelWorksheets>
<x:WindowHeight>4530</x:WindowHeight>
<x:WindowWidth>8505</x:WindowWidth>
<x:WindowTopX>480</x:WindowTopX>
<x:WindowTopY>120</x:WindowTopY>
<x:AcceptLabelsInFormulas/>
<x:ProtectStructure>False</x:ProtectStructure>
<x:ProtectWindows>False</x:ProtectWindows>
</x:ExcelWorkbook>
</xml><![endif]-->
</head>
<body link=blue vlink=purple>
<table x:str border=0 cellpadding=0 cellspacing=0 width=288 style='border-collapse:
collapse;table-layout:fixed;width:216pt'>
<col width=72 span=4 style='width:54pt'>
<tr height=19 style='height:14.25pt'>
<td height=19 width=72 style='height:14.25pt;width:54pt'>全球</td>
<td width=72 style='width:54pt'>問問</td>
<td width=72 style='width:54pt'>ee</td>
<td width=72 style='width:54pt'>rr</td>
</tr>
<tr height=19 style='height:14.25pt'>
<td height=19 style='height:14.25pt'>暗暗</td>
<td>ss</td>
<td>dd</td>
<td>ff</td>
</tr>
<![if supportMisalignedColumns]>
<tr height=0 style='display:none'>
<td width=72 style='width:54pt'></td>
<td width=72 style='width:54pt'></td>
<td width=72 style='width:54pt'></td>
<td width=72 style='width:54pt'></td>
</tr>
<![endif]>
</table>
</body>
</html>
中文問題:
查看源代碼時發現JSP文件中寫死的中文為亂碼,則在JSP文件頭部添加一行
<%@ page contentType="text/html; charset=gb2312" %>
查看源代碼時發現文字為中文,但是用Excel打開為亂碼則在<html>與<head>中加入
<meta http-equiv="Content-Type" content="text/html; charset=GBK">
在jsp頁面中,要在excel中顯示的內容可以從數據庫中讀取,在此就不做詳細的介紹了
在MSDN中fireEvent的描述很簡單:Fires a specified event on the object.
bFired = object.fireEvent(sEvent [, oEventObject])
并且MSDN給出了一個使用fireEvent的示例:




















這個示例非常的簡單,也完全說明了fireEvent的用法。不過這個示例有一點誤導我們,從而讓我們不容易發現frieEvent更有價值的使用方法。由于button的onclick事件被賦予語句:this.innerText = 'I have been clicked!',這里很容易誤導我們,fireEvent產生的是執行了btn.onclick()的效果。嗯,確實是這個效果,但是意義卻完全不同,btn.onclick()只是一個函數調用,它的執行必須依賴于用戶對其賦值,否則btn.onclick為null,是不能執行btn.onclick()的。而fireEvent('onclick')的效果,"等同于"鼠標在button元素上進行了點擊。
由于IE的事件處理是bubble up方式,fireEvent(sEvent)就顯得更加的有意義了,如果我們在一個table元素<table>中監聽事件,比如onclick,當點擊不同的td做出不同的響應時。如果使用程序來模擬,只能使用fireEvent這種方式,示例如下:










使用abc.onclick()和def.onclick()將得到"Object doesn't support this property or method"異常。
abc | def |
知道了fireEvent的用法,那么我們用它來做什么呢?在開發具有復雜事件處理動作組件時。有時我們需要從程序中去觸發一個本身因該鼠標或鍵盤觸發的事件,比如在TreeView控件中,我們一般是使用鼠標點擊來Expand&Collapse一個結點,如果我們要用程序代碼來實現這個操作怎么辦呢?當然直接執行事件處理函數是可以的,不過如果事件處理函數依賴于event變量中的狀態值,那么就必須使用fireEvent方法。
原來我曾經說過,因該把事件處理的函數封裝起來,便于直接調用。比如上面說到的TreeView節點的Expand和Collapse,我在TreeView控件中都是把它們封裝成兩個函數Expand和Collapse,在節點被點擊時,執行:








這樣一來,在程序中控制Expand和Collapse也就是分別執行函數而已。不過后來發現既然DOM中有fireEvent方法,似乎我在"
轉載:http://www.cnblogs.com/birdshome/archive/2005/04/07/128182.html
例如,在頁面加載完成以后,需要觸發一個onChange事件,在js中用document.getElementById("se").value="ttt";直接給select或text賦值是不行的,要想實現手動觸發onchange事件,需要在js給select賦值后,加入下面的語句,(假設select的id為sel)
document.getElementById("sel").fireEvent('onchange') 來實現,
例子:
<select id="sel" name="test" onchange="demo()">
<option value="1" selected>測試一</option>
<option value="2">測試二</option>
<option value="3">測試三</option>
<option value="4">測試四</option>
</select>
<input id="tex" type="text" name="text1" id="text1">
<script>
document.getElementById("sel").value="3";
document.getElementById("sel").fireEvent("onchange");
function demo()
{
var d=document.getElementById("sel").value;
document.getElementById("tex").value=d;
//alert(d);
}
</script>
</body></html>
上面的代碼產生的效果就相當于鼠標在select元素上進行了選擇,模仿出了select的onchange效果
如果在eclipse中誤刪除了文件,可以通過eclipse自己恢復,但是有時間限制,只能恢復當前時間前七天的,
在eclipse中,右鍵點擊刪除的項目名,選擇 restore from local history...,可以恢復七天內刪除的文件
使用common-fieupload 實現文件上傳,有時會遇到文件名或者是表單內容是亂碼,
1 調用FileUpload.settingHeaderEncoding("UTF-8"),這項設置可以解決路徑或者文件名為亂碼的問題。
2 在取字段值的時候,用FileItem.getString("UTF-8"),這項設置可以解決獲取的表單字段為亂碼的問題
http://jadclipse.sourceforge.net/wiki/index.php/Main_Page
選擇適合版本的jar文件下載
然后根據Installation 的說明安裝配置
1,把下載的 JadClipse JAR 文件放在Eclipse安裝目錄的plugins文件夾下,(我本機的路徑是D:\MyEclipse 6.0\eclipse\plugins)
2,重啟Eclipse,
3,下載jad,http://www.varaneckas.com/jad ,選擇適合的版本,
4,把 jad.exe 放在系統路徑中,(例如 C:\Program Files\Jad\jad.exe),然后 在Eclipse中選擇Window > Preferences... > Java > JadClipse > Path to Decompiler,填寫jad.exe的路徑,在Directory for tempcrary files中填寫臨時文件路徑,如下圖

5,選擇,Window > Preferences... > General > Editors > File Associations 選擇*.class文件,如下圖

選擇 Associated editors 選中 JadClipse class File Viewer ,選擇右邊的 Default 按鈕,如下圖

當 JadClipse class File Viewer 變為 defaule之后,如下圖

至此,jadClipse插件就安裝完成了,你可以雙擊 class文件 或者是把鼠標放在想看的類或方法名上,然后按住ctrl點擊,就可以看到反編譯后的源文件了,
一,如果你不在集群環境下使用,并且用到了hibernate,那么可以用hibernate提供的產生自動增長類型主鍵的increment策略,如下
在**.hbm.xml(hibernate映射文件)中配置如下
<class name="com.xx.xx.Test" table="TEST">
<id name="id" type="int" column="ID">
//該句指定使用hibernate自帶的increment策略生成主鍵
<generator class="increment"/>
</id>
<property name="uname" type="java.lang.String" column="UNAME"/>
</class>
這樣,在java文件中對表增加記錄時,只需添加除ID外的其他字段,然后save即可,
注意 ,increment 實現機制為在當前應用實例中維持一個變量,以保存著當前的最大值,之后每次需要生成主鍵的時候將此值加1作為主鍵,increment不能在集群環境下使用,
二,使用hibernate的sequence策略,在oracle中新建一個sequence,在hibernate中使用,如下
在**.hbm.xml(hibernate映射文件)中配置如下
<class name="com.xx.xx.Test" table="TEST">
<id name="id" type="int" column="ID">
//該句指定使用hibernate自帶的sequence策略生成主鍵 ,TEST_SEQ是在數據庫中新建的sequence的名稱
<generator class="sequence">
<param name="sequence">TEST_SEQ</param>
</generator>
<property name="uname" type="java.lang.String" column="UNAME"/>
</class>
這樣,在java文件中對表增加記錄時,只需添加除ID外的其他字段,然后save即可,
三,以上兩種方法都是通過hibernate實現的,下面給出ORACLE的一種實現方式
1. 建立 SEQUENCE
CREATE [ OR REPLACE ] SEQUENCE sequence_identity START WITH initial seed INCREMENT BY step MAXVALUE upper bound [NOMAXVALUE] NOCYCLE [empty]
2. 建立 TRIGGER
CREATE [ OR REPLACE ] TRIGGER trigger_identity BEFORE INSERT ON table_name FOR EACH ROW BEGIN SELECT sequence_identity.NEXTVAL INTO :new.column_name FROM DUAL; END;
這樣,在java文件中對表增加記錄時,只需添加除ID外的其他字段,然后save即可,