校园春色亚洲色图_亚洲视频分类_中文字幕精品一区二区精品_麻豆一区区三区四区产品精品蜜桃

主頁 > 知識庫 > jsp SmartUpload 實現(xiàn)上傳功能代碼

jsp SmartUpload 實現(xiàn)上傳功能代碼

熱門標簽:汝南縣地圖標注app 福建電銷貓機器人收費 湖北地圖標注公司 甘肅銷售電銷機器人公司 外呼直播語音系統(tǒng) 地圖標注專業(yè)和非專業(yè) 四川正規(guī)外呼系統(tǒng)軟件 山東ai外呼電銷機器人好用嗎 智能電話機器人銷售話術(shù)
復(fù)制代碼 代碼如下:

%@ page contentType="text/html;charset=gb2312"%>
html>
head>
meta http-equiv="Content-Type" content="text/html; charset=gb2312">
/head>
body leftmargin="0" topmargin="0" bgcolor="#ffffff">
form action="upfilea.jsp" method="post" name="form1"
enctype="multipart/form-data">
input name="FileName" type="FILE" size="30">
input type="submit" name="Submit" value="上傳" >
/form>
/body>
/html>
上傳頁面
%@ page contentType="text/html;charset=gb2312"%>
%@ page import="java.sql.*"%>
%@ page import="java.util.*"%>
%@ page import="java.io.*"%>
%@ page import="com.jspsmart.upload.*" %>
%
//實例化上載bean
com.jspsmart.upload.SmartUpload mySmartUpload=new
com.jspsmart.upload.SmartUpload();
//初始化
mySmartUpload.initialize(pageContext);
//設(shè)置上載的最大值
mySmartUpload.setMaxFileSize(500 * 1024*1024);
//上載文件
mySmartUpload.upload();
//循環(huán)取得所有上載的文件
for (int i=0;i mySmartUpload.getFiles().getCount();i++)
{
//取得上載的文件
com.jspsmart.upload.File myFile = mySmartUpload.getFiles().getFile(i);
if (!myFile.isMissing())
{
//取得上載的文件的文件名
String myFileName=myFile.getFileName();
//取得不帶后綴的文件名
String suffix=myFileName.substring(0,myFileName.lastIndexOf('.'));
//取得后綴名
String ext= mySmartUpload.getFiles().getFile(0).getFileExt();
if(!(ext.equals("gif")||ext.equals("jpg")||ext.equals("wmv")
||ext.equals("avi")||ext.equals("swf"))){
out.print(" script language='javascript'>!--
alert('上傳失敗,圖片格式為
GIF或者JPG,視頻格式為WMV或者AVI,falsh為swf請重試!');
// -->/script>");
out.print(" script language='javascript'>!--
window.location.href =
'uploadb.jsp'
// -->/script>");
}else
{
//取得文件的大小
int fileSize=myFile.getSize();
//保存路徑
String aa=getServletContext().getRealPath("/")+"upload/";
Random mynum=new Random(1);
int num=mynum.nextInt(10000);
num=(int)Math.random()*10000;
java.text.SimpleDateFormat formatter = new java.text.SimpleDateFormat
("yyMMddhhmmss");
java.util.Date date=new java.util.Date();
String days=formatter.format(date);
days=days+num;
//System.out.println("days="+days);
//System.out.println("pre="+pre);
//取得別的參數(shù)
request.setCharacterEncoding("GB2312");
/*if(request.getSession(true).getAttribute("id")!="")
{
id = request.getSession(true).getAttribute("id").toString();
}
myFile.saveAs("upload/"+days+myFile.getFileName());
String pic="upload/"+days+myFile.getFileName();*/
myFile.saveAs("upload/"+days+"6."+ext);
String pic="upload/"+days+"6."+ext;
session.setAttribute("pic",pic);
out.print(" script
language='javascript'>!--
parent.heheForm.pic.value='"+pic+"';
// -->/script>");
out.print(" script language='javascript'>!--
alert('上傳成功');
// -->/script>");
//下面的是將上載的文件保存到數(shù)據(jù)庫中
//將文件保存在服務(wù)器端
//將文件寫到數(shù)據(jù)庫中
//response.sendRedirect("uploada.jsp");
}}else{out.print(" script language='javascript'>!--
alert('文件上傳失
敗!');location=''
// -->/script>");}}
//與前面的if對應(yīng)
%>
html>
head> /head>
body leftmargin="0" topmargin="0" bgcolor="#ffffff">
form>
input type="text" name="pic" value=" %=session.getAttribute("pic")%>"
size="30">
/form>
/body>
/html>
您可能感興趣的文章:
  • jsp SmartUpload 中文亂碼問題解決

標簽:臨沂 黔東 白銀 昌都 南充 肇慶 吳忠 梅州

巨人網(wǎng)絡(luò)通訊聲明:本文標題《jsp SmartUpload 實現(xiàn)上傳功能代碼》,本文關(guān)鍵詞  jsp,SmartUpload,實現(xiàn),上傳,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《jsp SmartUpload 實現(xiàn)上傳功能代碼》相關(guān)的同類信息!
  • 本頁收集關(guān)于jsp SmartUpload 實現(xiàn)上傳功能代碼的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    主站蜘蛛池模板: 长子县| 长阳| 丰镇市| 石屏县| 辽宁省| 江西省| 靖宇县| 堆龙德庆县| 山阳县| 咸宁市| 辽源市| 玉龙| 修武县| 萨嘎县| 江华| 贵阳市| 抚州市| 公主岭市| 龙州县| 镇原县| 美姑县| 兴安县| 永靖县| 赫章县| 壤塘县| 忻城县| 株洲市| 辽中县| 石屏县| 扬州市| 花莲市| 康马县| 阿勒泰市| 永善县| 定边县| 信阳市| 临潭县| 六枝特区| 哈巴河县| 余庆县| 祁东县|