一、首先下载jspsmartupload组件 http://dboy520.51.net/cgi-bin/newjavajia/downcount.php?id=22 (本站地址) http://www.jspsmart.com 二、将目录jspsmartupload/wib_inf/classes中的内容拷贝到网站所在的实际目录中的WEB-INF中(resin是这个目录,其他的可能是classes,具体请查阅jspsmartupload/help/setup.htm) 三、如果是resin运行JSP,请在resin的conf/resin.conf中的 <web-app>和</web-app>中加入: <path-mapping url-pattern=’/upload/*’ real-path=’f:\jsp\jspsmartupload\upload’/> 四、上传界面的代码如下:(文件名:insert.htm) <FORM METHOD="POST" ACTION=" uploadfile.jsp" ENCTYPE="multipart/form-data"> <INPUT TYPE="FILE" NAME="FILE1" SIZE="50"><BR> <INPUT TYPE="FILE" NAME="FILE2" SIZE="50"><BR> <INPUT TYPE="FILE" NAME="FILE3" SIZE="50"><BR> <INPUT TYPE="FILE" NAME="FILE4" SIZE="50"><BR> 主题:<input type="text" name="text1" ><br> <INPUT type=submit value=写 完 name=ok> </form> 注意上面的real-path目录 五、uploadfile.jsp的代码如下: <%@page contentType="text/html;charset=gb2312" language="java" import="com.jspsmart.upload.*"%> <jsp:useBean id="mySmartUpload" scope="page" class="com.jspsmart.upload.SmartUpload" /> <HTML> <BODY > <H1>文件上传JSP</H1> <HR> <% int count=0; //定义目标目录 String destination="/upload/"; mySmartUpload.initialize(pageContext); //文件上传 mySmartUpload.upload(); //获得文本的内容 String content = mySmartUpload.getRequest().getParameter("text1"); //显示文本的内容 out.println(content); //上传的情况统计 for (int i=0;i<mySmartUpload.getFiles().getCount();i++){ com.jspsmart.upload.File myFile = mySmartUpload.getFiles().getFile(i); if (!myFile.isMissing()){ myFile.saveAs(destination+ myFile.getFileName()); out.println("文件名称= " + myFile.getFieldName() + "<BR>"); out.println("文件大小= " + myFile.getSize() + "<BR>"); out.println("文件名称= " + myFile.getFileName() + "<BR>"); out.println("文件大小= " + myFile.getFileExt() + "<BR>"); out.println("文件路径名= " + myFile.getFilePathName() + "<BR>"); out.println("文件类型= " + myFile.getContentType() + "<BR>"); out.println("ContentDisp = " + myFile.getContentDisp() + "<BR>"); out.println("MIME类型 = " + myFile.getTypeMIME() + "<BR>"); out.println("SubTypeMIME = " + myFile.getSubTypeMIME() + "<BR>"); count ++; } } out.println("<BR>可以上传" + mySmartUpload.getFiles().getCount() + "个文件<BR>"); out.println(count + "个文件已经被上传"); %> </BODY> </HTML> 以上就是JSP文件上传的全过程,Good Luck! |