<%@page contentType="text/html;charset=gb2312"%>
package
/**
* 此處插入類型描述
* 創建日期
* @author
*/
import javax
import javax
import java
import java
import javax
public class FLServlet extends javax
/**
* FLServlet 構造子注解
*/
public FLServlet() {
super();
}
protected void doGet(
javax
javax
throws javax
doPost(request
}
protected void doPost(HttpServletRequest request
throws javax
//上傳文件
FileLoad fl = new FileLoad();
fl
}
}
package
/**
* 此處插入類型描述
* 創建日期
* @author
*/
import javax
import javax
import java
import java
import javax
public class FileLoad {
public ServletInputStream sis = null;
public byte[] b = new byte[
public String sourcefile =
private int count =
public double size = Double
public String suffix =
public String objectfilename =
public String objectpath =
public boolean successful = true;
/**
* FileLoad 構造子注解
*/
public FileLoad() {
super();
}
/**
* 此處插入方法描述
* 創建日期
* @param response javax
*/
public void prepareForFile(HttpServletRequest request) {
try {
sis = request
int a =
int k =
String s =
while ((a = sis
//判斷是否從文件中讀到內容
{
s = new String(b
if ((k = s
//傳過來的每個文件中都有
{
s = s
k = s
s = s
sourcefile = s;
k = s
suffix = s
transferFile();
}
}
} catch (Exception ex) {
ex
}
}
/**
* 此處插入方法描述
* 創建日期
* @param i int
*/
public void transferFile() {
String x = Long
try {
objectfilename = x +
FileOutputStream out = new FileOutputStream(objectpath + objectfilename);
int a =
int k =
long hastransfered =
String s =
while ((a = sis
s = new String(b
if ((k = s
break;
}
sis
while ((a = sis
s = new String(b
if ((b[
&& (b[
&& (b[
&& (b[
&& (b[
break;
out
hastransfered += a;
if (hastransfered >=
System
successful = false;
break;
}
++count;
}
if (!successful) {
//如果傳送文件沒有成功就刪除掉這個文件
out
sis
String tem = objectpath + objectfilename;
File del = new File(tem);
del
}
out
} catch (IOException ioe) {
System
}
}
}
From:http://tw.wingwit.com/Article/program/Java/Javascript/201311/11138.html