文件上传使用:http://www.javazoom.net 的 UploadBean JAVA包,他的文件上传做的还不错,可进行目录或数据库的文件上传,默认使用的是O RACLE 的LONGRAW子段类型,可使用BLOB类型,但需要使用扩展JAVA包,LONGRAW子段最 大长度为2GB,并且一个表内只允许出现一个LONGRAW型子段,不过已经够我用了,而BL OB型子段最大为4GB,而且没有表中出现次数的限制。备注:想用他下载的组件Downloa d4J 1.0,我劝还是别做梦了,在功能上不太适合用在数据库下载。 文件下载使用的是:http://www.jspsmart.com的SmartUpload JAVA包,该包即可 以文件上传,也可以文件下在,而且使用也比较方便,不过我在这里只使用文件从数据 库下载功能,有兴趣的朋友可以试试。 下面我把使用这两个包的源CODE给大家说一下,以后大家碰道这些问题就不用象 我一样发愁了,哎!多伟大的人呀!大家给点掌声安慰我这个受伤的孤独男人吧!
文件上传: 实际上这些JAVA包都有使用的例子,不过我还是要贴出来。
文件名:ChineseDatabaseUpload.jsp
文件内容:
<html>
<%@ page language="java" contentType="text/html; charset=gb2312" import="jav
azoom.upload.*,java.util.*" %>
<%@ page errorPage="ExceptionHandler.jsp" %>
<jsp:useBean id="upBean" scope="application" class="javazoom.upload.UploadBe
an" >
<%
Properties props = new Properties();
props.put("user","cepic");
props.put("password","lpsc");
upBean.setDatabasestore("oracle.jdbc.driver.OracleDriver","jdbc:oracle:thin:
@10.231.234.252:1521:cepic",props); //数据库连接
%>
</jsp:useBean>
<head>
<title>中文上传</title>
<meta http-equiv="Content-Type" content="text/html; charset="gb2312">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<ul><font size="-1" face="Verdana, Arial, Helvetica, sans-serif">
<%
request.setCharacterEncoding("gb2312");
if (MultipartFormDataRequest.isMultipartFormData(request))
{
// Uses MultipartFormDataRequest to parse the HTTP request.
MultipartFormDataRequest mrequest = new MultipartFormDataRequest(request,nul
l,100*1024*1024,MultipartFormDataRequest.COSPARSER,"gb2312");
String todo = mrequest.getParameter("todo");
if ( (todo != null) && (todo.equalsIgnoreCase("upload")) )
{
Hashtable files = mrequest.getFiles();
if ( (files != null) || (!files.isEmpty()) )
{
UploadFile file = (UploadFile) files.get("uploadfile");
out.println("<li>Form field(表格栏): uploadfile"+"<BR> Uploaded file(已上传的
文件名称): "+file.getFileName()+" ("+file.getFileSize()+" bytes)"+"<BR> Cont
ent Type(文件类别)"+file.getContentType());
//out.println("<li>Form field: uploadfile"+"<BR> Uploaded file: "+file.getFi
leName()+" ("+file.getFileSize()+" bytes)"+"<BR> Content Type"+file.getConte
ntType());
// Uses the bean now to store specified by jsp:setProperty at the top.
upBean.store(mrequest, "uploadfile");
}
else
{
out.println("<li>No uploaded files");
}
out.println("<BR> gb2312 Text(简体) = "+mrequest.getParameter("gb2312txt"));
}
else out.println("<BR> todo="+todo);
}
%>
</font></ul>
<form method="post" action="ChineseDatabaseUpload.jsp" name="upform" enctype
="multipart/form-data">
<table width="60%" border="0" cellspacing="1" cellpadding="1" align="cente
r">
<tr>
<td align="left"><font size="-1" face="Verdana, Arial, Helvetica, sans
-serif"><b>请选择上传文件:</b></font></td>
</tr>
<tr>
<td align="left"><font size="-1" face="Verdana, Arial, Helvetica, sans
-serif">
<input type="file" name="uploadfile" size="50">
</font></td>
</tr>
<tr>
<td align="left"><font size="-1" face="Verdana, Arial, Helvetica, sans
-serif">
gb2312 text:
<input type="text" name="gb2312txt" size="20">
</font></td>
</tr>
<tr>
<td align="left"><font size="-1" face="Verdana, Arial, Helvetica, sans
-serif">
<input type="hidden" name="todo" value="upload">
<input type="submit" name="Submit" value="上传">
<input type="reset" name="Reset" value="取消">
</font></td>
</tr>
</table>
<br>
<br>
<table width="90%" border="0" cellspacing="1" cellpadding="0" align="cente
r">
<tr>
<td bgcolor="#666666">
<table width="100%" border="0" cellspacing="1" cellpadding="0" align
="center">
<tr>
<td bgcolor="#FFFFFF"><font size="-1" face="Verdana, Arial, Helv
etica, sans-serif"><b><font color="#0000FF"> Needed
HTML tags :</font></b></font></td>
</tr>
<tr>
<td bgcolor="#FFFFFF"><font size="-1" face="Verdana, Arial, Helv
etica, sans-serif"> <<b>form</b>
<b>method</b>="<b><font color="#FF0000">post</font></b>"
<b>action</b>="<b><font color="#FF0000">ChineseUpload.jsp</fon
t></b>"
name="upload" <b>enctype</b>="<b><font color="#FF0000">multipa
rt/form-data</font></b>"></font></td>
</tr>
<tr>
<td bgcolor="#FFFFFF"><font size="-1" face="Verdana, Arial, Helv
etica, sans-serif"> <<b>input</b>
<b>type</b>="<b><font color="#FF0000">file</font></b>"
<b>name</b>="<font color="#FF0000"><b>uploadfile</b></font>"
size="50"></font></td>
</tr>
</table>
</td>
</tr>
</table>
<p> </p>
<p> </p>
<p align="center"> </p>
<p align="center"> </p>
<p align="center"> </p>
<p align="center"> </p>
</form>
</body>
</html>
该ORACLE的表结构,在该网站上找吧!很简单就三个子段而已。
文件下载: 文件名:jspsmartdownload.jsp
文件内容:
<meta http-equiv="Content-Type" content="application/msword; charset=gb2312"
> //注意这里,如果你没有设置成“GB2312”结果你会明白的。
<%@ page language="java" import="java.sql.*,com.jspsmart.upload.*"%>
<jsp:useBean id="mySmartUpload" scope="page" class="com.jspsmart.upload.Smar
tUpload" />
<%
Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
Connection con = DriverManager.getConnection("jdbc:oracle:thin10.231.234.2
52:1521:cepic", "cepic", "lpsc");
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM UPLOADS");
if (rs.next()){
mySmartUpload.initialize(pageContext);
mySmartUpload.downloadField(rs,"BINARYFILE","application/msword","");
//mySmartUpload.fieldToFile(rs,"BINARYFILE","c:/sample.DOC");
}
rs.close();
stmt.close();
con.close();
%>
查看本文来源