日期:2014-05-18  浏览次数:20664 次

在JSP中用SmartUpload如何实现上传、下载,特别急用!!!求大家帮忙
在JSP中用SmartUpload如何实现上传、下载,特别急用!!!求大家帮忙!

------解决方案--------------------
百度是不是更适合楼主呢
http://dev.csdn.net/article/73/73651.shtm

------解决方案--------------------
楼上的 sunyujia 说得很对。
网络上有很多jspSmartUpload的学习资料。

这里还有一篇:
http://www.knowsky.com/3136.html
很详细。既有API说明,又有示例代码。应该可以帮助楼主解决问题。呵呵。
------解决方案--------------------
我得资源里有很好得上传组件


------解决方案--------------------
开源的,网上可以参考的东西太多了,给你贴段我自己的代码
doup.jsp
<%@ page contentType="text/html;charset=gb2312"%>
<%@ page import="com.jspsmart.upload.File"%>
<%@ page import="com.jspsmart.upload.Files"%>
<%@ page import="java.util.Calendar;"%>
<jsp:useBean id="myup" class="com.jspsmart.upload.SmartUpload" />
<jsp:useBean id="mydb" class="com.wootion.DB" />
<center>
正在上传文件,请稍等……
</center>
<%
Calendar cal = Calendar.getInstance();
String filedir = "/file/";
String errors = "";
String sql = "";
long maxsize = 2 * 1024 * 1024;
try
{
myup.initialize(pageContext);
myup.setMaxFileSize(maxsize);
myup.upload();
Files files = myup.getFiles();
for (int i = 0; i < files.getCount(); i++)
{
File singlefile = files.getFile(i);
if (!singlefile.isMissing())
{
String info = myup.getRequest().getParameter(
"info" + (i + 1));
if (info == null || info.equals(""))
info = "无描述信息!";
String type = singlefile.getContentType();
sql = "insert into tb_file values('"
+ singlefile.getFileName() + "','','" + type
+ "','" + info + "','" + cal.get(Calendar.YEAR)
+ "年" + (cal.get(Calendar.MONTH) + 1) + "月"
+ cal.get(Calendar.DAY_OF_MONTH) + "日" + "')";
int num = mydb.CUD(sql);
if (num <= 0)
{
errors += "<li>文件" + (i + 1)
+ "上传失败:请检查是否输入了非法字符!</li>";
}
else
{
sql = "select MAX(id) as maxid from tb_file";
java.sql.ResultSet rs = mydb.Read(sql);

String destname = "";
if (rs.next())
{
int maxid = rs.getInt("maxid");
destname = maxid + "."
+ singlefile.getFileExt();
sql = "update tb_file set file_save='"
+ destname + "' where id=" + maxid;
num = mydb.CUD(sql);
if (num <= 0)
{
errors += "<li>