工程的目录结构以及所需要的jar包:
1.index.jsp页面如下:
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>upload</title> <script type="text/javascript"> function reload_filepath(path) { document.certForm.de_file_path.value = path; } </script> </head> <body> <h1>上传证件</h1> <form action="" name="certForm" method="post"> <table border="1" cellpadding="0" cellspacing="0"> <tr> <td> 保存路径: </td> <td> <input name="de_file_path" size="50" maxlength="200" readonly="true" /> </td> <td> <a href="#" onClick='JavaScript:window.open("upload.jsp?type=cert_file&agid=00393","","top=200,left=300,width=300,height=130")'>[上传证书]</a> </td> </tr> </table> </form> </body> </html>
2.upload.jsp页面如下:
<%@ page contentType="text/html;charset=GBK"%> <html> <head> <title>文件上传</title> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> </head> <body> 获取参数:<%=request.getQueryString() %> <form action="upload_post.jsp?<%=request.getQueryString()%>" method="post" enctype="multipart/form-data" name="form1"> <input name="file_data" type="file" id="file_data"> <input type="submit" name="Submit" value="上传"> </form> <center><input type=button value="关闭" onclick="javascript:window.close()"></center> </body> </html>
3.upload_post.jsp页面如下:
<%@ page contentType="text/html;charset=GBK"%> <%@ page import="java.io.*"%> <%@ page import="java.util.*"%> <%@ page import="com.hsp.base.Configuration" %> <%@page import="com.hsp.base.Constants"%> <%@page import="com.hsp.util.LoggerUtils"%> <jsp:useBean id="mySmartUpload" scope="page" class="com.jspsmart.upload.SmartUpload" /><!--jsp:useBean标签用于在JSP页面创建bean实例,相当于new--> <% //--- 上传模块 --- String Msg = ""; long MaxFileSize = 1000000; //System.out.println("start-------------------------------------"); try { String field = request.getParameter("type"); String filename = ""; String new_filename = ""; mySmartUpload.initialize(pageContext); mySmartUpload.upload(); com.jspsmart.upload.File myFile = mySmartUpload.getFiles().getFile(0); LoggerUtils.recordInfo(Constants.SMART_WEB_LOG, myFile.getFileName()); if (myFile.getSize() < MaxFileSize) { if (!myFile.isMissing()) { String TimeStamp = String.valueOf((new Date()).getTime()); String path = ""; if (field.equalsIgnoreCase("cert_file")) { path = Configuration.getFile_upload_path();//获取文件上传路径 LoggerUtils.recordInfo(Constants.SMART_WEB_LOG, path); TimeStamp = request.getParameter("agid") + "_" + TimeStamp; LoggerUtils.recordInfo(Constants.SMART_WEB_LOG, TimeStamp); } filename = myFile.getFileName(); //上传文件重命名 String[] arr_filename = filename.split("\\.");//需要转义一下,这里不能使用split(".") LoggerUtils.recordInfo(Constants.SMART_WEB_LOG, "数组长度:"+arr_filename.length); LoggerUtils.recordInfo(Constants.SMART_WEB_LOG, "文件名拆分:"+ arr_filename[0]+"---"+arr_filename[1]); String temp_filename = arr_filename[0]+"_"+TimeStamp; LoggerUtils.recordInfo(Constants.SMART_WEB_LOG, "文件名temp_filename:"+ temp_filename); new_filename = temp_filename + "." + arr_filename[1]; LoggerUtils.recordInfo(Constants.SMART_WEB_LOG, "文件名new_filename:"+ new_filename); File file = new File(path, new_filename); myFile.saveAs(file.getAbsolutePath()); Msg = "上传成功!"; } else { Msg = "上传不成功![<a href=javascript:history.back()>返回</a>]"; } } else { Msg = "体积过大![<a href=javascript:history.back()>返回</a>]"; } if (field.equalsIgnoreCase("cert_file") && Msg.equalsIgnoreCase("上传成功!")) { %> <Script language="JavaScript"> //window.opener指的是调用window.open()函数的窗口,这个页面需要有reload_filepath函数 window.opener.reload_filepath("<%=new_filename%>"); window.close(); </Script> <% } } catch(Exception e) { LoggerUtils.recordInfo(Constants.SMART_SYS_LOG, "gaowegiang"+e.getMessage()); Msg = "上传失败:" +e.getMessage(); } %> <body> <br> <center> <%out.print("<font size=2>" + Msg + "</font>");%><BR><BR> <input type=button value="关闭" onclick="javascript:window.close()"> </center> </body>
相关推荐
JSPsmart文件上传jar包,很方便的文件上传实现功能jar包, 很实用,可以实现文件上传和下载
经过修改的 jspsmart插件,能够很好的支持包含中文名称的上传和下载。但是要注意中文名称中如果包含了空格,需要自己先去出空格,才能保证上传和下载文件正常。
jspsmart文件上传与邮件发送的实例.docx
jspsmart实现文件上传下载及jspSmartUploadjar下载文库.pdf
jspSmart组件实现文件上传 jspSmart组件实现文件上传 jspSmart组件实现文件上传 jspSmart组件实现文件上传 jspSmart组件实现文件上传 jspSmart组件实现文件上传 jspSmart组件实现文件上传 jspSmart组件实现文件上传
jspsmart实现文件上传下载及jspSmartUpload.jar下载.txt jspsmart实现文件上传下载及jspSmartUpload.jar下载.txt
jspsmart 上传下载实例里面有jspsmart源码,解决了乱码问题
jspSmartUpload是由www.jspsmart.com网站开发的一个可免费使用的全功能的文件上传下载组件,适于嵌入执行上传下载操作的JSP文件中。该组件有以下几个特点: 1、使用简单。在JSP文件中仅仅书写三五行JAVA代码就可以...
这是一个基于Jsp的文件上传项目。项目非常简单明了,直接导入Ecplise运行,在upload.html中选择需要上传的文件,跳转到do_upload.jsp执行上传命令
用jspSmart实现文件上传到数据库的实例,前台用jsp实现,后台用java实现,资源中还带有jspsmart.jar
WEBOFFICE组件jspsmart上传文件组件源码
jspsmart,JSP文件上传组件,实用
直接可以运用的上传下载文件组件,jspsmart,而且提供数据库读写类,直接将上传下载文件信息写到数据库里面
运用该jar包可以使用SmartUpload组建实现文件上传。由www.jspsmart.com网站开发的一个可免费使用的全功能的文件上传下载工具。
网上有很多文章都是jspsmart,由于jspsmart直接在内存中操作数据,如果上传大文件或多台计算机上传的话会出错,还有一些方法传得比较慢。 为了方便上传文件,本人写了一个传输文件类。 附有一个显示进度条的例子和...
jspsmart文件上传与邮件发送的实例,需要的朋友可以参考一下
JSP Smart Upload,基于JSP的文件上传
只所以提供这个类,是因为对于文件上传表单,通过request对象无法获得表单项的值,必须通过jspSmartUpload组件提供的Request对象来获取。该类提供如下方法: 1、getParameter 作用:获取指定参数之值。当参数不...
jspsmart实现文件上传下载及jspSmartUploadjar下载文库.rar