国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JSP > 正文

使用JSP/Servlet上載文件

2024-09-05 00:20:26
字體:
供稿:網(wǎng)友
使用 jsp/ servlet上載文件正成為一項(xiàng)常用的任務(wù)。以下是一個(gè)簡單的例程,使用了jspsmart的一個(gè)免費(fèi)的組件。你可以在jspsmart站點(diǎn)進(jìn)行下載。

1. html file
<html>
<body>
<script language="javascript" src="jsfunction.js">
</script>
<script language="javascript">
<!--
function checkform(){

if (document.uploadform.adsimage.value==""){
alert("you must choose what image file to upload!");
return false;
}
document.uploadform.submit();
}
function cancelupload(){
window.close();
window.opener.focus();
}
//-->
</script>
<form name="uploadform" method="post"
action="uploadimage.jsp" enctype="multipart/form-data"
target=_self>
<center>
<table border="1" width="65%">
<tr>
<td colspan=2 nowrap align=center>廣告圖片上載</td>

</tr>
<tr>
<td width="15%" nowrap >廣告圖片:</td>
<td width="50%" nowrap><input type="file"
name="adsimage" size="20"></td>
</tr>
<tr>
<td align="center" colspan=2 >
<input type="button" value="upload" >
   
<input type="button" value="cancel" >
</td>

</tr>
</form>
</table>
<!--
<a href="javascript:window.close();">close this window</a>
-->
<script language="javascript">
<!--
this.focus();
//-->
</script>
</body>

2. jsp file
<%@ page language="java" import="com.jspsmart.upload.*,
java.sql.*,java.util.* "%>
<%-- use smartupload bean --%>
<jsp:usebean id="mysmartupload" scope="page"
class="com.jspsmart.upload.smartupload" />

<%

//initialization
mysmartupload.init(config);
mysmartupload.service(request,response);

//set restriction
mysmartupload.setallowedfileslist("gif,bmp,jpeg,jpg");
mysmartupload.settotalmaxfilesize(51200);



// upload
try{
mysmartupload.upload();
}
catch(exception e){
out.println("<font color=red>upload file fail!</font>
<a href=
"javascript:window.history.back();">back</a><br>");
out.println("<ui>notes:</ui>");

out.println("<ul>you must set correct file
name.</ul>");
out.println("<ul>you file size must be less than
50k.</ul>");
out.println("<ul>you can only upload .gif .jpeg .jpg and
.bmp files.</ul>");

return;

}
//save file to disk
mysmartupload.getfiles().getfile(0).saveas("/" +
"filename");

 

%>



3. servlet file (you can do it yourself)


資料來源:碧波山莊visual basic http://ctsvb.126.com


收集最實(shí)用的網(wǎng)頁特效代碼!

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 壶关县| 山阳县| 昭觉县| 紫云| 抚松县| 吉安市| 兴隆县| 贵州省| 翼城县| 滨州市| 武隆县| 泽州县| 丹东市| 洞头县| 天长市| 上虞市| 响水县| 六安市| 饶平县| 宁国市| 德保县| 海盐县| 雷山县| 静安区| 肥西县| 永德县| 广丰县| 福安市| 盘锦市| 浮山县| 阿克陶县| 石狮市| 宿迁市| 修水县| 东港市| 广东省| 永州市| 民乐县| 浮山县| 化德县| 二连浩特市|