java使用smartupload組件實(shí)現(xiàn)文件上傳的方法(2)_JSP教程
推薦:jsp利用application統(tǒng)計(jì)在線人數(shù)的方法這篇文章主要介紹了jsp利用application統(tǒng)計(jì)在線人數(shù)的方法,代碼中備有較為詳盡的注釋便于理解,是比較實(shí)用的技巧,需要的朋友可以參考下 本文實(shí)例講述了jsp利用application統(tǒng)計(jì)在線人數(shù)的方法。分享給大家供大家參考。 具體實(shí)現(xiàn)方法如下: 代碼如下:%@ page language=jav
smartupload是由www.jspsmart.com網(wǎng)站開發(fā)的一套上傳組件包,可以輕松的實(shí)現(xiàn)文件的上傳及下載功能,smartupload組件使用簡(jiǎn)單、可以輕松的實(shí)現(xiàn)上傳文件類型的限制、也可以輕易的取得上傳文件的名稱、后綴、大小等。
smartupload本身是一個(gè)系統(tǒng)提供的jar包(smartupload.jar),用戶直接將此包放到classpath下即可,也可以直接將此包拷貝到TOMCAT_HOME\lib目錄之中。
下面使用組件完成上傳
單一文件上傳:
代碼如下: <html><head><title>smartupload組件上傳</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /></head>
<body>
<form action="smartupload_demo01.jsp" method="post" enctype="multipart/form-data">
圖片<input type="file" name="pic">
<input type="submit" value="上傳">
</form>
</body>
</html>
jsp代碼:
smartupload_demo01.jsp
代碼如下: <%@ page contentType="text/html" pageEncoding="utf-8"%><%@ page import="com.jspsmart.upload.*" %>
<html>
<head><title>smartupload組件上傳01</title></head>
<body>
<%
SmartUpload smart = new SmartUpload() ;
smart.initialize(pageContext) ; // 初始化上傳操作
smart.upload(); // 上傳準(zhǔn)備
smart.save("upload") ; // 文件保存
out.print("上傳成功");
%>
</body>
</html>
批量上傳:
html文件
代碼如下: <html>
<head><title>smartupload組件上傳02</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /></head>
<body>
<form action="smartupload_demo02.jsp" method="post" enctype="multipart/form-data">
圖片<input type="file" name="pic1"><br>
圖片<input type="file" name="pic2"><br>
圖片<input type="file" name="pic3"><br>
<input type="submit" value="上傳">
<input type="reset" value="重置">
</form>
</body>
</html>
jsp代碼
smartupload_demo02.jsp
代碼如下: <%@ page contentType="text/html" pageEncoding="utf-8"%><%@ page import="com.jspsmart.upload.*"%>
<%@ page import="com.zhou.study.*"%>
<html>
<head><title>smartupload組件上傳02</title></head>
<body>
<%
SmartUpload smart = new SmartUpload() ;
smart.initialize(pageContext) ; // 初始化上傳操作
smart.upload() ; // 上傳準(zhǔn)備
String name = smart.getRequest().getParameter("uname") ;
IPTimeStamp its = new IPTimeStamp("192.168.1.1") ; // 取得客戶端的IP地址
for(int x=0;x<smart.getFiles().getCount();x++){
String ext = smart.getFiles().getFile(x).getFileExt() ; // 擴(kuò)展名稱
String fileName = its.getIPTimeRand() + "." + ext ;
smart.getFiles().getFile(x).saveAs(this.getServletContext().getRealPath("/")+"upload"+java.io.File.separator + fileName) ;
}
out.print("上傳成功");
%>
</body>
</html>
注意:在TOMCAT_HOME/項(xiàng)目目錄下建立upload文件夾才能正常運(yùn)行!
簡(jiǎn)單上傳操作上傳后的文件名稱是原本的文件名稱�?赏ㄟ^工具類重命名。
分享:jsp分頁(yè)顯示完整實(shí)例這篇文章主要介紹了jsp分頁(yè)顯示完整實(shí)例,以文章管理頁(yè)面為例詳細(xì)分析了jsp的分頁(yè)顯示實(shí)現(xiàn)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下 本文實(shí)例講述了jsp分頁(yè)顯示的實(shí)現(xiàn)方法。分享給大家供大家參考。 具體實(shí)現(xiàn)方法如下: 代碼如下:%@ page contentType=text/html;
- jsp利用application統(tǒng)計(jì)在線人數(shù)的方法
- jsp分頁(yè)顯示完整實(shí)例
- JSP 開發(fā)環(huán)境搭建
- JSP 生命周期
- jsp中URL傳遞中文參數(shù)的處理方法
- JSP 重置按鈕清空傳入的表單數(shù)據(jù)實(shí)例
- JSP中的倒數(shù)計(jì)時(shí)和自動(dòng)跳轉(zhuǎn)頁(yè)面
- JSP 獲取Spring 注入對(duì)象示例
- jsp文件怎么打開?
- JSP自定義標(biāo)簽的實(shí)現(xiàn)過程
- JSP教程:tomcat6關(guān)于EL表達(dá)式的一個(gè)錯(cuò)誤
- JSP上面實(shí)現(xiàn)目錄壓縮
JSP教程Rss訂閱編程教程搜索
JSP教程推薦
- 在J2ME網(wǎng)絡(luò)編程中使用CMWAP代理
- JSP網(wǎng)站開發(fā)環(huán)境的目錄結(jié)構(gòu)標(biāo)準(zhǔn)
- 詳細(xì)講解Linux系統(tǒng)下JDK、Tomcat的安裝
- 什么是模式?什么是框架?
- 加快JDBC中JSP數(shù)據(jù)庫(kù)的訪問速度
- JSP頁(yè)面中文傳遞參數(shù)使用escape編碼
- AJAX實(shí)現(xiàn)web頁(yè)面級(jí)聯(lián)菜單
- jsp include引用非本級(jí)目錄網(wǎng)頁(yè)實(shí)現(xiàn)代碼
- JSP 相關(guān)對(duì)象的使用介紹
- 淺談Java 使用jdbc:odbc 建立無(wú)源連接access數(shù)據(jù)庫(kù)
猜你也喜歡看這些
- MVC模式在j2me項(xiàng)目中的應(yīng)用一
- Struts2訪問servlet分享
- jsp連接數(shù)據(jù)庫(kù)oracle
- 在無(wú)線J2ME設(shè)備上實(shí)現(xiàn)HTTP協(xié)議1
- 基于JSP 自定義標(biāo)簽使用實(shí)例介紹
- Sun微系統(tǒng)預(yù)計(jì)下一代Java手機(jī)技術(shù)年內(nèi)將問世
- Linux下Apache與Tomcat整合的簡(jiǎn)單方法
- JSP由淺入深11—— 標(biāo)記庫(kù)
- 解密21種Java開發(fā)中應(yīng)避免的錯(cuò)誤
- JSP新手入門初級(jí)教程之JSP概述
- 相關(guān)鏈接:
復(fù)制本頁(yè)鏈接| 搜索java使用smartupload組件實(shí)現(xiàn)文件上傳的方法(2)
- 教程說明:
JSP教程-java使用smartupload組件實(shí)現(xiàn)文件上傳的方法(2)
。