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 现如今,使用JSP和Servlet上传文件正成为一种广泛的手段。下面就是一个使用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");