js|servlet Use JSP and Servlet to Upload file to server is becoming a
common task now.
Below is a simple example use the jspsmart free component which
implements it.
You can download the free package from JSPSMART
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>
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");