JSP上面實(shí)現(xiàn)目錄壓縮_JSP教程
推薦:JSP中表單數(shù)據(jù)存儲(chǔ)的一種通用方法兩種常見的表單數(shù)據(jù)存儲(chǔ)處理方法 1、對每一表單都編寫相應(yīng)的程序代碼 在JSP頁面或JavaBean或Servlet中,使用request. getparameter()函數(shù)逐一提取表單提交的數(shù)據(jù),或編寫相應(yīng)的JavaBean,使用setProperty方法將數(shù)據(jù)自動(dòng)取到JavaBean中,然后生成SQL語句(insert,updat
zip方法 zipPath參數(shù)為保存zip的文件路徑 srcPath參數(shù)為需要壓縮的目錄 在linux window上面測試無問題!主要是編碼問題比較麻煩~要是有其他異常 請留言 或者 有什么更好的方法 歡迎給更多的意見
//zip zhe folder
void zip(String zipPath, String srcPath,javax.servlet.jsp.JspWriter out) throws Exception {
FileOutputStream output = null;
ZipOutputStream zipOutput = null;
try{
output = new FileOutputStream(zipPath);
zipOutput = new ZipOutputStream(output);
zipEntry(zipOutput,srcPath,srcPath,zipPath);
}catch(Exception e){
out.print("file zip error");
}finally{
if(zipOutput!=null)zipOutput.close();
}
out.print("zip ok"+zipPath);
}
//add the zip entry
void zipEntry(ZipOutputStream zipOs, String initPath,String filePath,String zipPath) throws Exception {
String entryName = filePath;
File f = new File(filePath);
if (f.isDirectory()){// ??
String[] files = f.list();
for(int i = 0; i < files.length; i++)
zipEntry(zipOs, initPath, filePath + File.separator + files[i],zipPath);
return;
}
String chPh = initPath.substring(initPath.lastIndexOf("/") + 1);// ?????
int idx=initPath.lastIndexOf(chPh);
if (idx != -1) {
entryName = filePath.substring(idx);
}
ZipEntry entry;
entry = new ZipEntry(entryName);
File ff = new File(filePath);
if(ff.getAbsolutePath().equals(zipPath))return;
entry.setSize(ff.length());
entry.setTime(ff.lastModified());
//the CRC efficacy
entry.setCrc(0);
CRC32 crc = new CRC32();
crc.reset();
zipOs.putNextEntry(entry);
int len = 0;
byte[] buffer = new byte[2048];
int bufferLen = 2048;
FileInputStream input =null;
try{
input = new FileInputStream(filePath);
while ((len = input.read(buffer, 0, bufferLen)) != -1) {
zipOs.write(buffer, 0, len);
crc.update(buffer, 0, len);
}
}catch(Exception e){
}finally{
if(input!=null)input.close();
}
entry.setCrc(crc.getValue());
}
分享:JSP中的pageEncoding和contentType屬性關(guān)于JSP頁面中的pageEncoding和contentType兩種屬性的區(qū)別: pageEncoding是jsp文件本身的編碼 contentType的charset是指服務(wù)器發(fā)送給客戶端時(shí)的內(nèi)容編碼 JSP要經(jīng)過兩次的編碼,第一階段會(huì)用pageEncoding,第二階段會(huì)用utf-8至utf-8,第三階段就是由Tomcat出來的網(wǎng)頁,
- JSP中表單數(shù)據(jù)存儲(chǔ)的一種通用方法
- JSP中的pageEncoding和contentType屬性
- jsp用jdbc連接db2數(shù)據(jù)庫的方法
- 用JSP+JavaScript打造二級級聯(lián)下拉菜單
- 在JSP環(huán)境中配置使用fckeditor詳細(xì)講解
- JSP中include指令和include行為的區(qū)別
- JSP獲取客戶端的瀏覽器和操作系統(tǒng)信息
- Java程序員要掌握的十個(gè)JSP中的標(biāo)簽庫
- 構(gòu)造JSP/Javabean開發(fā)和發(fā)布環(huán)境的方法
- 通過JSP預(yù)編譯消除性能瓶頸
- 用JSP實(shí)現(xiàn)數(shù)據(jù)庫圖片的存儲(chǔ)與顯示實(shí)例
- 在JSP頁面中的應(yīng)用JavaBean
- 相關(guān)鏈接:
- 教程說明:
JSP教程-JSP上面實(shí)現(xiàn)目錄壓縮
。