<form method="POST" action="saveFile.jsp" enctype="multipart/form-data" name="fileInfo">
<P><strong><font face="宋体">
文件类型:Word文档、Exe文件或Zip文件</font></strong></P>
软件名称:<INPUT name="recordNumber">
<P><input type="file" name="doc" size="60"></P>
<p><input type="submit" onclick="checkDocType(this.form); return MM_returnvalue" name="submit" value="正式提交"></p>
</form>
saveFile.jsp<html>
<head>
<title>软件上传</title>
<%@ page contentType="text/html;charset=gb2312"%>
<jsp:useBean id="kSave" scope ="session" class="up.KingUpload" />
</head>
<body aLink=#3333ff bgColor=#edfafc leftMargin=0 link=#3333ff text=#000066 topMargin=0 vLink=#3333ff MARGINHEIGHT="0" MARGINWIDTH="0">
<%
try{
kSave.init(request,response);
kSave.setPath(application.getRealPath(""),"Files/");
kSave.clean();
}catch(Exception e){
out.println(e.getMessage());
}
%>package up;import java.io.*;
import java.sql.*;
import javax.servlet.*;public class KingUpload
{ public KingUpload()
{
message = "no message";
} public void KingUpload()
{
} public void init(ServletRequest servletrequest, ServletResponse servletresponse)
{
req = servletrequest;
res = servletresponse;
} public void setPath(String s, String s1)
{
mainPath = s.replace('\\', '/');
lowPath = s1.replace('\\', '/');
System.out.println("path=" + mainPath + lowPath);
} public void saveTo()
{
byte abyte0[] = new byte[200];
byte abyte1[] = new byte[4096];
byte abyte2[] = new byte[1];
String s6 = "";
long l = req.getContentLength();
String s = req.getContentType();
System.out.println("contentlength=" + l);
System.out.println("contentType=" + s);
boolean flag = false;
int j = 0;
int k = 0;
String s4 = "";
String s5 = "";
String s3 = "";
try
{
in = req.getInputStream();
}
catch(IOException ioexception) { }
for(int i1 = 1; i1 < 9; i1++)
try
{
int i = in.readLine(abyte0, 0, 200);
j += i;
String s1 = new String(abyte0, 0, i);
System.out.print(s1);
if(i1 == 1)
{
byte abyte3[] = new byte[i - 2];
for(int k2 = 0; k2 < i - 2; k2++)
abyte3[k2] = abyte0[k2]; s3 = new String(abyte3);
}
if(i1 == 4)
{
s4 = new String(abyte0, 0, i - 2);
System.out.println("Append:studentID=" + s4);
}
if(i1 == 6)
{
String s2 = new String(abyte0, i - 6, 3);
s2 = s2.toLowerCase();
if(s2.equals("doc"))
k = 1;
else
if(s2.equals("zip"))
k = 2;
else
if(s2.equals("exe"))
k = 3;
else
k = 4;
}
}
catch(Exception exception) { } System.out.println("File Data Begin,tLen=" + j);
if(k == 1)
s5 = s4 + ".doc";
else
if(k == 2)
s5 = s4 + ".zip";
else
if(k == 3)
s5 = s4 + ".exe";
else
s5 = s4;
s6 = lowPath + s5;
try
{
String s7 = mainPath + s6;
outfile = new FileOutputStream(s7, false);
}
catch(IOException ioexception1)
{
System.out.println("file create error!" + ioexception1.getMessage());
}
long l1 = l - (long)j - 200L;
long l2 = (int)((double)l1 / 4096D);
long l3 = l1 - l2 * 4096L;
if(l1 > 0x800000L)
{
try
{
outfile.close();
File file = new File(mainPath + s6);
if(file.exists())
file.delete();
l1 = in.skip(l1);
}
catch(Exception exception1)
{
System.out.println("file close error");
}
message = "\u7CFB\u7EDF\u4E0D\u63A5\u53D7\u5927\u4E8E8M\u7684\u6587\u4EF6!";
}
else
{
try
{
System.out.println("block number=" + l2);
System.out.println("remain=" + l3);
for(int j1 = 0; (long)j1 < l2; j1++)
{
for(int i3 = 0; i3 < 4096; i3++)
{
in.read(abyte2, 0, 1);
abyte1[i3] = abyte2[0];
} outfile.write(abyte1);
System.out.print(".");
} byte abyte4[] = new byte[(int)l3];
for(int k1 = 0; (long)k1 < l3; k1++)
{
in.read(abyte2, 0, 1);
abyte4[k1] = abyte2[0];
} outfile.write(abyte4);
for(int i2 = 0; i2 < 200; i2++)
{
in.read(abyte2, 0, 1);
abyte0[i2] = abyte2[0];
} char ac[] = new char[200];
for(int j2 = 0; j2 < 200; j2++)
ac[j2] = (char)abyte0[j2]; String s8 = new String(ac);
int j3 = s8.indexOf(s3);
System.out.println("last=" + j3);
outfile.write(abyte0, 0, j3 - 2);
outfile.close();
saveInfoToDB(s4, k, s6);
message = "\u6587\u4EF6\u63D0\u4EA4\u6210\u529F\uFF01";
}
catch(IOException ioexception2)
{
System.out.println("data-transfer or file-close error");
}
}
} public void clean()
{
req = null;
res = null;
}
ServletRequest req;
ServletResponse res;
int recordNumber;
ServletInputStream in;
FileOutputStream outfile;
String mainPath;
String lowPath;
public String message;
}自己在研究研究吧
<P><strong><font face="宋体">
文件类型:Word文档、Exe文件或Zip文件</font></strong></P>
软件名称:<INPUT name="recordNumber">
<P><input type="file" name="doc" size="60"></P>
<p><input type="submit" onclick="checkDocType(this.form); return MM_returnvalue" name="submit" value="正式提交"></p>
</form>
saveFile.jsp<html>
<head>
<title>软件上传</title>
<%@ page contentType="text/html;charset=gb2312"%>
<jsp:useBean id="kSave" scope ="session" class="up.KingUpload" />
</head>
<body aLink=#3333ff bgColor=#edfafc leftMargin=0 link=#3333ff text=#000066 topMargin=0 vLink=#3333ff MARGINHEIGHT="0" MARGINWIDTH="0">
<%
try{
kSave.init(request,response);
kSave.setPath(application.getRealPath(""),"Files/");
kSave.clean();
}catch(Exception e){
out.println(e.getMessage());
}
%>package up;import java.io.*;
import java.sql.*;
import javax.servlet.*;public class KingUpload
{ public KingUpload()
{
message = "no message";
} public void KingUpload()
{
} public void init(ServletRequest servletrequest, ServletResponse servletresponse)
{
req = servletrequest;
res = servletresponse;
} public void setPath(String s, String s1)
{
mainPath = s.replace('\\', '/');
lowPath = s1.replace('\\', '/');
System.out.println("path=" + mainPath + lowPath);
} public void saveTo()
{
byte abyte0[] = new byte[200];
byte abyte1[] = new byte[4096];
byte abyte2[] = new byte[1];
String s6 = "";
long l = req.getContentLength();
String s = req.getContentType();
System.out.println("contentlength=" + l);
System.out.println("contentType=" + s);
boolean flag = false;
int j = 0;
int k = 0;
String s4 = "";
String s5 = "";
String s3 = "";
try
{
in = req.getInputStream();
}
catch(IOException ioexception) { }
for(int i1 = 1; i1 < 9; i1++)
try
{
int i = in.readLine(abyte0, 0, 200);
j += i;
String s1 = new String(abyte0, 0, i);
System.out.print(s1);
if(i1 == 1)
{
byte abyte3[] = new byte[i - 2];
for(int k2 = 0; k2 < i - 2; k2++)
abyte3[k2] = abyte0[k2]; s3 = new String(abyte3);
}
if(i1 == 4)
{
s4 = new String(abyte0, 0, i - 2);
System.out.println("Append:studentID=" + s4);
}
if(i1 == 6)
{
String s2 = new String(abyte0, i - 6, 3);
s2 = s2.toLowerCase();
if(s2.equals("doc"))
k = 1;
else
if(s2.equals("zip"))
k = 2;
else
if(s2.equals("exe"))
k = 3;
else
k = 4;
}
}
catch(Exception exception) { } System.out.println("File Data Begin,tLen=" + j);
if(k == 1)
s5 = s4 + ".doc";
else
if(k == 2)
s5 = s4 + ".zip";
else
if(k == 3)
s5 = s4 + ".exe";
else
s5 = s4;
s6 = lowPath + s5;
try
{
String s7 = mainPath + s6;
outfile = new FileOutputStream(s7, false);
}
catch(IOException ioexception1)
{
System.out.println("file create error!" + ioexception1.getMessage());
}
long l1 = l - (long)j - 200L;
long l2 = (int)((double)l1 / 4096D);
long l3 = l1 - l2 * 4096L;
if(l1 > 0x800000L)
{
try
{
outfile.close();
File file = new File(mainPath + s6);
if(file.exists())
file.delete();
l1 = in.skip(l1);
}
catch(Exception exception1)
{
System.out.println("file close error");
}
message = "\u7CFB\u7EDF\u4E0D\u63A5\u53D7\u5927\u4E8E8M\u7684\u6587\u4EF6!";
}
else
{
try
{
System.out.println("block number=" + l2);
System.out.println("remain=" + l3);
for(int j1 = 0; (long)j1 < l2; j1++)
{
for(int i3 = 0; i3 < 4096; i3++)
{
in.read(abyte2, 0, 1);
abyte1[i3] = abyte2[0];
} outfile.write(abyte1);
System.out.print(".");
} byte abyte4[] = new byte[(int)l3];
for(int k1 = 0; (long)k1 < l3; k1++)
{
in.read(abyte2, 0, 1);
abyte4[k1] = abyte2[0];
} outfile.write(abyte4);
for(int i2 = 0; i2 < 200; i2++)
{
in.read(abyte2, 0, 1);
abyte0[i2] = abyte2[0];
} char ac[] = new char[200];
for(int j2 = 0; j2 < 200; j2++)
ac[j2] = (char)abyte0[j2]; String s8 = new String(ac);
int j3 = s8.indexOf(s3);
System.out.println("last=" + j3);
outfile.write(abyte0, 0, j3 - 2);
outfile.close();
saveInfoToDB(s4, k, s6);
message = "\u6587\u4EF6\u63D0\u4EA4\u6210\u529F\uFF01";
}
catch(IOException ioexception2)
{
System.out.println("data-transfer or file-close error");
}
}
} public void clean()
{
req = null;
res = null;
}
ServletRequest req;
ServletResponse res;
int recordNumber;
ServletInputStream in;
FileOutputStream outfile;
String mainPath;
String lowPath;
public String message;
}自己在研究研究吧
<%@include file="protect.jsp"%>
<%@ page language="java" import="com.jspsmart.upload.*"%>
<%@ page import="java.util.Date" %>
<%@ page import="java.sql.*"%>
<%@ page import="java.lang.*" %><jsp:useBean id="mySmartUpload" scope="page" class="com.jspsmart.upload.SmartUpload" />
<jsp:useBean id="sqlbean" scope="page" class="beans.sql_data"/><HTML>
<link rel="stylesheet" type="text/css" href="../bbs/bbs03.css">
<BODY BGCOLOR="white"><H3>文件上传结果:</H3>
<HR><%
mySmartUpload.initialize(pageContext);
mySmartUpload.upload();
com.jspsmart.upload.File myFile = mySmartUpload.getFiles().getFile(0);
if (!myFile.isMissing())
{
String myfilename= null;
String sql="";
myfilename=myFile.getFileName();
String fname =myFile.getFileName();
String suffix=myfilename.substring(0,myfilename.lastIndexOf('.'));
String suffix1=myfilename.substring(myfilename.lastIndexOf('.'));
String explain=(String)mySmartUpload.getRequest().getParameter("text");
explain=new String(explain.getBytes("UTF-8"),"UTF-8");
String ts="/product/"+fname;
myFile.saveAs(ts);
String filename=myFile.getFileName();
out.println("说明: " + explain+ "<BR>");
out.println("文件大小: " + myFile.getSize() + "<BR>");
out.println("文件名称:" + fname+ "<BR>");
out.println("文件类型:" + myFile.getFileExt() + "<BR>");
out.println("本地文件路径: " + myFile.getFilePathName() + "<BR>");
sql="insert into upload(id,explain,filename) values(se_dzzw.nextval,'"+explain+"','"+fname+"')";
sqlbean.executeQuery(sql);
out.println("<font color=red>上传数据库成功!</font>");
}%><p align="center">
<input type="button" name="Submit" value="返回" onClick="history.back()">
</p></BODY>
</HTML>