|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
java是一种面向对象的编程语言,优点是可移植性比较高,最初设计时就是本着一次编写到处执行设计的。可以开发各种应用程序和游戏,不过速度没有c++快,所以一般是不用java来编写应用程序和电脑游戏。js|servletUseJSPandServlettoUploadfiletoserverisbecominga
commontasknow.
Belowisasimpleexampleusethejspsmartfreecomponentwhich
implementsit.
YoucandownloadthefreepackagefromJSPSMART
1.HtmlFile
<html>
<body>
<scriptLANGUAGE="javascript"SRC="JSFunction.js">
</script>
<scriptlanguage="JavaScript">
<!--
functioncheckForm(){
if(document.uploadform.adsImage.value==""){
alert("Youmustchoosewhatimagefiletoupload!");
returnfalse;
}
document.uploadform.submit();
}
functioncancelUpload(){
window.close();
window.opener.focus();
}
//-->
</script>
<formname="uploadform"method="post"
action="uploadImage.jsp"ENCTYPE="multipart/form-data"
target=_self>
<center>
<tableborder="1"width="65%">
<tr>
<tdcolspan=2nowrapalign=center>告白图片上载</td>
</tr>
<tr>
<tdwidth="15%"nowrap>告白图片:</td>
<tdwidth="50%"nowrap><inputtype="file"
name="adsImage"size="20"></td>
</tr>
<tr>
<tdalign="center"colspan=2>
<inputtype="button"value="upload"onclick="return
checkForm();">
<inputtype="button"value="Cancel"onclick="return
cancelUpload();">
</td>
</tr>
</form>
</table>
<!--
<ahref="Javascript:window.close();">closethiswindow</a>
-->
<scriptlanguage="JavaScript">
<!--
this.focus();
//-->
</script>
</body>
2.JSPFile
<%@pagelanguage="java"import="com.jspsmart.upload.*,
java.sql.*,java.util.*"%>
<%--useSmartUploadbean--%>
<jsp:useBeanid="mySmartUpload"scope="page"
class="com.jspsmart.upload.SmartUpload"/>
<%
//Initialization
mySmartUpload.init(config);
mySmartUpload.service(request,response);
//SetRestriction
mySmartUpload.setAllowedFilesList("gif,bmp,jpeg,jpg");
mySmartUpload.setTotalMaxFileSize(51200);
//Upload
try{
mySmartUpload.upload();
}
catch(Exceptione){
out.println("<fontcolor=red>UploadFileFail!</font>
<ahref=
"JavaScript:window.history.back();">back</a><br>");
out.println("<UI>Notes:</UI>");
out.println("<UL>YoumustsetcorrectFile
Name.</UL>");
out.println("<UL>Youfilesizemustbelessthan
50K.</UL>");
out.println("<UL>Youcanonlyupload.Gif.jpeg.jpgand
.bmpfiles.</UL>");
return;
}
//savefiletodisk
mySmartUpload.getFiles().getFile(0).saveAs("/"+
"FileName");
%>
3.ServletFile(youcandoityourself)
Java到底会发战成什么样,让我们拭目以待吧,我始终坚信着java会更好。以上都是俺个人看法,欢迎大家一起交流. |
|