根据网上的一个上传范例做的,可是怎么也不传,大家帮我看看吧

dyfh 2004-10-22 11:19:13
运行后不提示出错,但并没有文件上传到数据库,帮我看看是怎么回事吧

<%@ page contentType="text/html;charset=gb2312" %>
<%@ page import="com.oreilly.servlet.MultipartRequest" %>
<%@ page import="java.sql.*" %>
<%@ page import="java.io.*" %>
<%@ page import="java.util.*" %>
<%@ page import="javax.servlet.*" %>
<%@ page import="javax.servlet.http.*" %>

<%
String dllname = request.getParameter("dllname");
String info=request.getParameter("info");
if (dllname==null) dllname="";
if (info==null) info="";
String opertid=request.getParameter("opertid");
String opername="驱动管理";
if (opertid==null) opertid="none";
if (opertid!="none"){
if (opertid.equals("add")){
String s = null;
byte temp [];
String Name = "";
String s1 = request.getHeader("Content-Type");
String s2 = request.getContentType();
if (s1 == null && s2 != null)
s = s2;
else if(s2 == null && s1 != null)
s = s1;
else if(s1 != null && s2 != null)
s = (s1.length() <= s2.length())? s2:s1;

if( s != null && s.toLowerCase().startsWith("multipart/form-data"))
{
String dir=".\\";
// 上传档案大小限制
int size=100*1024*1024;
MultipartRequest mr=new MultipartRequest(request,dir,size);

String fileName = "";
Enumeration filesname = mr.getFileNames();
while (filesname.hasMoreElements())
{
String name = (String) filesname.nextElement();
fileName = mr.getFilesystemName(name);
temp=fileName.getBytes("iso-8859-1");
Name = new String(temp);
}

java.io.File file=null;
file = new java.io.File(fileName);
java.io.InputStream inStream = new java.io.FileInputStream(file);
long filesize=file.length();

Class.forName("oracle.jdbc.driver.OracleDriver");
Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@192.168.0.129:1521:qq","qq", "qq");
String strSql = "insert into QQ_DRIVER values('" + Name + "'," + filesize +", '"+ info +"',sysdate,?)";
PreparedStatement stmt = conn.prepareStatement(strSql);
stmt.setBinaryStream(1,inStream,size);

int i= stmt.executeUpdate();
inStream.close();
stmt.close();
}
}
}
%>
<body bgcolor="#CCCCCC" onMouseMove="javaScript:OffNum=0">
<div id="bkdiv" >
<form name='frmDriver' action='driver.jsp' method='post' enctype='multipart/form-data'>
<table height="100%" width="100%" border=0 cellpadding="0" cellspacing="1">
<%@ include file="phstop.jsp"%>
<tr>
<td width="100%" height="1" align=Left><font color=#000000 size="2" face="宋体"></font><td>
</tr>

<tr>
<td valign="top" width="100%" height="97%" bgcolor="#FFFFFF" >
<table BGCOLOR="#EFEFEF" width="100%" border=0 cellpadding="0" cellspacing="0">
<tr>
<td ><font color=blue size="2" face="宋体">
文件名:<input type='file' name='filename' size='25'>
说明:<input name="info" value=''>   
<input name="btnAdd" type="button" onClick="onAdd()" VALUE="添加">   
</font>
</td>
</tr>
<tr bgcolor="#C7D7F3" >
<td height="20"><font size="2" face="宋体">总数:<Strong><%=vlst.size()-1%></Strong></font>    
</td>
</tr>
</table>
<td>
</tr>
</table>
<input type="hidden" name="dllname" value=<%=dllname%>>
<input type="hidden" name="opertid" value=<%=opertid%>>
<input type="hidden" name="clickstr" value="">
<input type="hidden" name="valuestr" value="">

</form>
</div>
<%PrintBarInfo(out);%>
<script language="JavaScript">
with(document.all.bkdiv.style){
left=(screen.width-800)/2;
}
</script>

</body>
</html>

<Script language="javascript">

function onAdd(){
frmDriver.opertid.value="add";
frmDriver.submit();
}

</Script>
...全文
87 点赞 收藏 9
写回复
9 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
debug148 2004-10-23
混个脸熟!
回复
dyfh 2004-10-22
哦?是吗?能推荐个地方找吗?一下子有点茫然而
回复
wuyue-tiger 2004-10-22
这段处理blob的代码是有问题的,你可以在网上找到相关的内容
回复
dyfh 2004-10-22
两个传的都是一样的文件,.dll类型的文件,一个行一个不行
回复
dyfh 2004-10-22
汗,传的就是.dll文件呀,我不打算传别的文件
回复
wuyue-tiger 2004-10-22
你传个非文本文件的二进制文件试试,一定不行的
回复
lenoli 2004-10-22
老兄,太多了,先帮你upup吧
回复
dyfh 2004-10-22
to tigeryu(吴越小虎) :
往oracle里入一个blob字段可以呀,看下面这段代码,就可以上传,也是oracle

<html>
<%@ page contentType="text/html;charset=gb2312" %>
<%@ page import="com.oreilly.servlet.MultipartRequest" %>
<%@ page import="java.sql.*" %>
<%@ page import="java.io.*" %>
<%@ page import="java.util.*" %>
<%@ page import="javax.servlet.*" %>
<%@ page import="javax.servlet.http.*" %>
<% String newname=request.getParameter("filename"); %>
<body>

<%

String s = null;
byte temp [];
String Name = "";
String s1 = request.getHeader("Content-Type");
String s2 = request.getContentType();
if (s1 == null && s2 != null)
s = s2;
else if(s2 == null && s1 != null)
s = s1;
else if(s1 != null && s2 != null)
s = (s1.length() <= s2.length())? s2:s1;

if( s != null && s.toLowerCase().startsWith("multipart/form-data"))
{
String dir=".\\";
// 上传档案大小限制
int size=100*1024*1024;
MultipartRequest mr=new MultipartRequest(request,dir,size);

String fileName = "";
Enumeration filesname = mr.getFileNames();
while (filesname.hasMoreElements())
{
String name = (String) filesname.nextElement();
fileName = mr.getFilesystemName(name);
temp=fileName.getBytes("iso-8859-1");
Name = new String(temp);
}

java.io.File file=null;
file = new java.io.File(fileName);
java.io.InputStream inStream = new java.io.FileInputStream(file);
long filesize=file.length();

Class.forName("oracle.jdbc.driver.OracleDriver");
Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@192.168.0.129:1521:qq","qq", "qq");
String strSql = "insert into QQ_DRIVER(dllname,dllsize,update_date,dllbody) values('" + Name + "'," + filesize + ",sysdate,?)";
PreparedStatement stmt = conn.prepareStatement(strSql);
stmt.setBinaryStream(1,inStream,size);

int i= stmt.executeUpdate();
inStream.close();
stmt.close();
out.println(Name);
out.println(filesize);
out.println("upload sucess");
}
%>
<form method='post' action='DBUpload.jsp' enctype='multipart/form-data'>
file name:<input type='file' name='filename' size='15'><br>
<input type='submit'><input type='reset'>
</form>
</body>
</html>

回复
wuyue-tiger 2004-10-22
com.oreilly.servlet.MultipartRequest 没用过,不知道上传处理对不对,不过往oracle里插入一个blob字段这样做应该是行不通的,别的数据库可以
回复
发动态
发帖子
Web 开发
创建于2007-09-28

7.9w+

社区成员

Java Web 开发
申请成为版主
社区公告
暂无公告