// Decompiled by DJ v3.7.7.81 Copyright 2004 Atanas Neshkov Date: 2004-9-28 23:56:53
// Home Page : http://members.fortunecity.com/neshkov/dj.html - Check often for new version!
// Decompiler options: packimports(3)
// Source File Name: upBean.java
package xiaoxiang.fileUpload;
import java.io.IOException;
import java.io.InputStream;
import java.util.Vector;
import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.jsp.PageContext;
// Referenced classes of package xiaoxiang.fileUpload:
// files, Request, file
public class upBean {
public upBean() {
m_files = new files();
m_totalBytes = 0;
m_currentIndex = 0;
m_startData = 0;
m_endData = 0;
m_boundary = new String();
m_totalMaxFileSize = 0L;
m_maxFileSize = 0L;
m_allowedExtList = new Vector();
m_allowedFileTypeList = new Vector();
m_formRequest = new Request();
m_count = 0;
isCover = true;
realPath = new String();
}
public final void initialize(PageContext pagecontext)
throws ServletException {
m_application = pagecontext.getServletContext();
m_request = (HttpServletRequest) pagecontext.getRequest();
m_response = (HttpServletResponse) pagecontext.getResponse();
}
/**
* @deprecated Method setRealPath is deprecated
*/
public void setRealPath(String pRealPath) {
realPath = pRealPath;
}
public String getRealPath() {
return realPath;
}
public void setIsCover(boolean pIsCover) {
isCover = pIsCover;
}
public void upload() throws ServletException, IOException, Exception {
int i = 0;
long maxSize = 0L;
boolean isBoundaryEnd = false;
String sFileName = new String();
String fileExtName = new String();
String dataFieldValue = new String();
String contentType = new String();
String typeMIME = new String();
String subTypeMIME = new String();
m_totalBytes = m_request.getContentLength();
m_binArray = new byte[m_totalBytes];
int j;
for (; i < m_totalBytes; i += j)
try {
m_request.getInputStream();
j =
m_request.getInputStream().read(
m_binArray,
i,
m_totalBytes - i);
} catch (Exception exception) {
throw new Exception("Unable to upload.");
}
for (;
!isBoundaryEnd && m_currentIndex < m_totalBytes;
m_currentIndex++)
if (m_binArray[m_currentIndex] == 13)
isBoundaryEnd = true;
else
m_boundary += (char) m_binArray[m_currentIndex];
if (m_currentIndex == 1)
return;
for (m_currentIndex++;
m_currentIndex < m_totalBytes;
m_currentIndex += 2) {
String dataHeader = getDataHeader();
m_currentIndex += 2;
boolean isFileObject = dataHeader.indexOf("filename") > 0;
String fieldName = getDataFieldValue(dataHeader, "name");
if (isFileObject) {
dataFieldValue = getDataFieldValue(dataHeader, "filename");
sFileName = getFileName(dataFieldValue);
fileExtName = getFileExt(sFileName);
contentType = getContentType(dataHeader);
typeMIME = getTypeMIME(contentType);
subTypeMIME = getSubTypeMIME(contentType);
}
getDataSection();
m_size = (m_endData - m_startData) + 1;
if (isFileObject && sFileName.length() > 0) {
if (!m_allowedExtList.isEmpty()
&& !m_allowedExtList.contains(fileExtName))
throw new SecurityException(
"\u60A8\u7684\u6587\u4EF6\u540E\u7F00\u540D\u4E0D\u7B26\u5408\u6211\u4EEC\u7684\u8BBE\u5B9A.\u6211\u4EEC\u53EA\u5141\u8BB8\u4EE5\u4E0B\u540E\u7F00\u540D\u7684\u6587\u4EF6\uFF1A"
+ m_allowedExtList.toString());
if (!m_allowedFileTypeList.isEmpty()
&& !m_allowedFileTypeList.contains(subTypeMIME))
throw new SecurityException(
"\u60A8\u7684\u6587\u4EF6\u7C7B\u578B\u4E0D\u7B26\u5408\u6211\u4EEC\u7684\u8BBE\u5B9A.\u6211\u4EEC\u53EA\u5141\u8BB8\u4EE5\u4E0B\u7C7B\u578B\u7684\u6587\u4EF6\uFF1A"
+ m_allowedFileTypeList.toString());
if (m_maxFileSize > 0L
&& (long) ((m_endData - m_startData) + 1) > m_maxFileSize)
throw new SecurityException(
"\u60A8\u4E0A\u4F20\u7684\u8FD9\u4E2A\u6587\u4EF6\u8D85\u8FC7\u4E86\u6211\u4EEC\u7684\u9650\u5236 : "
+ sFileName
+ ".\u6587\u4EF6\u7684\u5355\u4E2A\u5927\u5C0F\u5E94\u5C0F\u4E8E"
+ (m_maxFileSize / 1000L + 1L)
+ "kb");
maxSize += (m_endData - m_startData) + 1;
if (m_totalMaxFileSize > 0L && maxSize > m_totalMaxFileSize)
throw new SecurityException(
"\u60A8\u4E0A\u4F20\u7684\u6587\u4EF6\u603B\u5927\u5C0F\u8D85\u8FC7\u4E86\u6211\u4EEC\u7684\u9650\u5236:"
+ (m_totalMaxFileSize / 1000L + 1L)
+ "kb");
m_files.addFile(
new file(
sFileName,
m_startData,
(m_endData - m_startData) + 1,
m_count,
subTypeMIME,
this));
m_count++;
}
if (!isFileObject) {
String s11 =
new String(
m_binArray,
m_startData,
(m_endData - m_startData) + 1);
m_formRequest.putParameter(fieldName, s11);
}
if ((char) m_binArray[m_currentIndex + 1] == '-')
break;
}
}
private String getDataFieldValue(String s, String s1) {
String s2 = new String();
String s3 = new String();
int i = 0;
boolean flag = false;
boolean flag1 = false;
boolean flag2 = false;
s2 = s1 + "=" + '"';
i = s.indexOf(s2);
if (i > 0) {
int j = i + s2.length();
int k = j;
s2 = "\"";
int l = s.indexOf(s2, j);
if (k > 0 && l > 0)
s3 = s.substring(k, l);
}
return s3;
}
private String getFileExt(String s) {
String s1 = new String();
int i = 0;
int j = 0;
if (s == null)
return null;
i = s.lastIndexOf('.') + 1;
j = s.length();
s1 = s.substring(i, j);
if (s.lastIndexOf('.') > 0)
return s1;
else
return "";
}
private String getContentType(String s) {
String s1 = new String();
String s2 = new String();
int i = 0;
boolean flag = false;
s1 = "Content-Type:";
i = s.indexOf(s1) + s1.length();
if (i != -1) {
int j = s.length();
s2 = s.substring(i, j);
}
return s2;
}
private String getTypeMIME(String s) {
String s1 = new String();
int i = 0;
i = s.indexOf("/");
if (i != -1)
return s.substring(1, i);
else
return s;
}
private String getSubTypeMIME(String s) {
String s1 = new String();
int i = 0;
boolean flag = false;
i = s.indexOf("/") + 1;
if (i != -1) {
int j = s.length();
return s.substring(i, j);
} else {
return s;
}
}
private void getDataSection() {
boolean flag = false;
String s = new String();
int i = m_currentIndex;
int j = 0;
int k = m_boundary.length();
m_startData = m_currentIndex;
m_endData = 0;
while (i < m_totalBytes)
if (m_binArray[i] == (byte) m_boundary.charAt(j)) {
if (j == k - 1) {
m_endData = ((i - k) + 1) - 3;
break;
}
i++;
j++;
} else {
i++;
j = 0;
}
m_currentIndex = m_endData + k + 3;
}
private String getDataHeader() {
int i = m_currentIndex;
int j = 0;
boolean flag = false;
for (boolean flag1 = false; !flag1;)
if (m_binArray[m_currentIndex] == 13
&& m_binArray[m_currentIndex + 2] == 13) {
flag1 = true;
j = m_currentIndex - 1;
m_currentIndex += 2;
} else {
m_currentIndex++;
}
String s = new String(m_binArray, i, (j - i) + 1);
return s;
}
private String getFileName(String s) {
String s1 = new String();
String s2 = new String();
int i = 0;
boolean flag = false;
boolean flag1 = false;
boolean flag2 = false;
i = s.lastIndexOf('/');
if (i != -1)
return s.substring(i + 1, s.length());
i = s.lastIndexOf('\\');
if (i != -1)
return s.substring(i + 1, s.length());
else
return s;
}
public void setAllowedExtList(String s) {
String s1 = "";
if (s != null) {
String
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
eoa.rar (93个子文件)
eoa
.project 1KB
.mymetadata 282B
WebRoot
bean
Box.java 985B
Box.class 828B
insert.jsp 2KB
javaBeanJSP1.jsp 552B
Admin.java 2KB
.project 443B
newstyle.css 4KB
WEB-INF
.cvsignore 7B
web.xml 286B
src
.project 384B
.classpath 351B
lib
msbase.jar 225KB
mssqlserver.jar 48KB
msutil.jar 22KB
classes
bean
news.class 365B
shopBean.class 1KB
sampleBean.class 551B
Box.class 1KB
Admin.class 3KB
database
sql_data.class 2KB
sss.class 234B
news
functions.class 5KB
sql_data.class 3KB
strFormat.class 2KB
xiaoxiang
fileUpload
files.class 1KB
file.class 3KB
Request.class 2KB
upBean.class 9KB
util
TransFormat.class 970B
page.class 5KB
login.class 3KB
.cvsignore 4B
bottom.jsp 690B
uploadFiles
logom.gif 2KB
sample.jsp 438B
hot.jsp 3KB
index.jsp 11KB
META-INF
MANIFEST.MF 39B
work
org
apache
jsp
list.jsp 9KB
.tomcatplugin 359B
show.jsp 3KB
new.jsp 3KB
headbottom.jsp 531B
header.jsp 996B
shop.htm 392B
images
ico1.gif 53B
LIST.GIF 869B
icon_name.gif 311B
new_commend.gif 1KB
hot_p.gif 76B
jt.gif 1KB
more.gif 293B
download.gif 1KB
tongji.gif 4KB
color.jpg 16KB
line2.gif 50B
arrow.gif 53B
sword_org.gif 73B
logo.jpg 18KB
de1.gif 818B
new_more.gif 101B
sword03.gif 114B
sword02.gif 66B
Thumbs.db 10KB
ad.jpg 15KB
ad2.jpg 14KB
item1.gif 77B
icon_password.gif 247B
search.jsp 5KB
default.jsp 5KB
show2.jsp 2KB
.classpath 677B
shop.jsp 657B
.myeclipse
src
bean
Box.java 985B
shopBean.java 619B
sampleBean.java 193B
Admin.java 2KB
news.java 161B
sss.java 27B
database
sql_data.java 1KB
news
functions.java 7KB
sql_data.java 2KB
strFormat.java 2KB
xiaoxiang
fileUpload
Request.java 2KB
file.java 3KB
files.java 1KB
upBean.java 9KB
util
login.java 2KB
TransFormat.java 1008B
page.java 5KB
.classpath 552B
共 93 条
- 1
资源评论
sosysw
- 粉丝: 31
- 资源: 23
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功