package com.util;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Vector;
import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.PageContext;
public class SmartUpload
{
protected byte m_binArray[];
protected HttpServletRequest m_request;
protected HttpServletResponse m_response;
protected ServletContext m_application;
private int m_totalBytes;
private int m_currentIndex;
private int m_startData;
private int m_endData;
private String m_boundary;
private long m_totalMaxFileSize;
private long m_maxFileSize;
private Vector m_deniedFilesList;
private Vector m_allowedFilesList;
private boolean m_denyPhysicalPath;
//private boolean m_forcePhysicalPath;
private String m_contentDisposition;
public static final int SAVE_AUTO = 0;
public static final int SAVE_VIRTUAL = 1;
public static final int SAVE_PHYSICAL = 2;
private SmartFiles m_files;
private SmartRequest m_formRequest;
public SmartUpload()
{
m_totalBytes = 0;
m_currentIndex = 0;
m_startData = 0;
m_endData = 0;
m_boundary = ""; //new String();
m_totalMaxFileSize = 0L;
m_maxFileSize = 0L;
m_deniedFilesList = new Vector();
m_allowedFilesList = new Vector();
m_denyPhysicalPath = false;
//m_forcePhysicalPath = false;
m_contentDisposition = ""; //new String();
m_files = new SmartFiles();
m_formRequest = new SmartRequest();
}
/**
* @deprecated Method init is deprecated
*/
public final void init(ServletConfig servletconfig) throws ServletException
{
m_application = servletconfig.getServletContext();
}
/**
* @deprecated Method service is deprecated
*/
public void service(HttpServletRequest httpservletrequest,HttpServletResponse httpservletresponse) throws ServletException,IOException
{
m_request = httpservletrequest;
m_response = httpservletresponse;
}
public final void initialize(ServletConfig servletconfig,HttpServletRequest httpservletrequest,HttpServletResponse httpservletresponse) throws ServletException
{
m_application = servletconfig.getServletContext();
m_request = httpservletrequest;
m_response = httpservletresponse;
}
public final void initialize(PageContext pagecontext) throws ServletException
{
m_application = pagecontext.getServletContext();
m_request = (HttpServletRequest)pagecontext.getRequest();
m_response = (HttpServletResponse)pagecontext.getResponse();
}
/**
* @deprecated Method initialize is deprecated
*/
public final void initialize(ServletContext servletcontext,HttpSession httpsession,HttpServletRequest httpservletrequest,HttpServletResponse httpservletresponse,JspWriter jspwriter) throws ServletException
{
m_application = servletcontext;
m_request = httpservletrequest;
m_response = httpservletresponse;
}
public void upload() throws ServletException,IOException,SmartUploadException
{
int i = 0;
//boolean flag = false;
boolean flag1 = false;
//boolean flag2 = false;
long l = 0L;
//String s = "";//new String();
//String s2 = "";//new String();
String s4 = ""; //new String();
String s5 = ""; //new String();
String s6 = ""; //new String();
String s7 = ""; //new String();
String s8 = ""; //new String();
String s9 = ""; //new String();
String s10 = ""; //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 SmartUploadException("Unable to upload.");
}
}
for(;!flag1 && m_currentIndex < m_totalBytes;m_currentIndex++)
{
if(m_binArray[m_currentIndex] == 13)
{
flag1 = true;
}
else
{
m_boundary = m_boundary + (char)m_binArray[m_currentIndex];
}
}
if(m_currentIndex == 1)
{
return;
}
for(m_currentIndex++;m_currentIndex < m_totalBytes;m_currentIndex = m_currentIndex + 2)
{
long now=new java.util.Date().getTime();
String s1 = getDataHeader();
m_currentIndex = m_currentIndex + 2;
boolean flag3 = s1.indexOf("filename") > 0;
String s3 = getDataFieldValue(s1,"name");
if(flag3)
{
s6 = getDataFieldValue(s1,"filename");
s4 = now+getFileName(s6);
s5 = getFileExt(s4);
s7 = getContentType(s1);
s8 = getContentDisp(s1);
s9 = getTypeMIME(s7);
s10 = getSubTypeMIME(s7);
}
getDataSection();
if(flag3 && s4.length() > 0)
{
if(m_deniedFilesList.contains(s5))
{
throw new SecurityException("The extension of the file is denied to be uploaded (1015).");
}
if(!m_allowedFilesList.isEmpty() && !m_allowedFilesList.contains(s5))
{
throw new SecurityException("The extension of the file is not allowed to be uploaded (1010).");
}
if(m_maxFileSize > 0L && (long)((m_endData - m_startData) + 1) > m_maxFileSize)
{
throw new SecurityException("Size exceeded for this file : " + s4 + " (1105).");
}
l += (m_endData - m_startData) + 1;
if(m_totalMaxFileSize > 0L && l > m_totalMaxFileSize)
{
throw new SecurityException("Total File Size exceeded (1110).");
}
}
if(flag3)
{
SmartFile file = new SmartFile();
file.setParent(this);
file.setFieldName(s3);
file.setFileName(s4);
file.setFileExt(s5);
file.setFilePathName(s6);
file.setIsMissing(s6.length() == 0);
file.setContentType(s7);
file.setContentDisp(s8);
file.setTypeMIME(s9);
file.setSubTypeMIME(s10);
if(s7.indexOf("application/x-macbinary") > 0)
{
m_startData = m_startData + 128;
}
file.setSize((m_endData - m_startData) + 1);
file.setStartData(m_startData);
file.setEndData(m_endData);
m_files.addFile(file);
}
else
{
String s11 = new String(m_binArray,m_startData,(m_endData - m_startData) + 1);
m_formRequest.putParameter(s3,s11);
}
if((char)m_binArray[m_currentIndex + 1] == '-')
{
break;
}
}
}
p
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
开发语言: Java 技术框架: Servlet+bean 开发工具: MyEclipse,会Eclipse和Idea的都可以自由转换 数据库: Sqlserver2008R2或以上 相关资料: 有,在压缩包中
资源推荐
资源详情
资源评论
收起资源包目录
javaweb课程设计文档管理系统 (181个子文件)
ScriptResource.axd 254KB
ScriptResource(1).axd 64KB
WebResource.axd 20KB
SmartUpload.class 17KB
ComServlet.class 8KB
AdminBean.class 8KB
AdminServlet.class 7KB
SmartFile.class 6KB
UpServlet.class 4KB
ComBean.class 4KB
DBO.class 3KB
SystemBean.class 2KB
Common.class 2KB
SmartRequest.class 2KB
SmartFiles.class 2KB
MD5.class 1KB
Filter.class 975B
CheckCode.class 922B
Constant.class 674B
SmartUploadException.class 364B
.classpath 2KB
org.eclipse.wst.common.component 450B
org.eclipse.wst.jsdt.ui.superType.container 49B
public.css 3KB
public.css 2KB
index.css 1KB
login.css 617B
login.css 552B
论文.doc 496KB
1361197254296.doc 22KB
bg_login_panel.gif 25KB
bg.gif 5KB
bg_banner_menu.gif 4KB
bg_schedule.gif 2KB
main_hr.gif 2KB
bg_users.gif 1KB
default.gif 1KB
bg_table_item.gif 1KB
mail.gif 1KB
main_hl2.gif 1KB
minical_title.gif 1KB
bg_button_del.gif 1KB
bg_button_update.gif 1KB
bg_table_item2.gif 1KB
nav_help.gif 1KB
nav_search.gif 1KB
nav_print.gif 1KB
nav_forward.gif 1KB
nav_back.gif 1KB
nav_resetPassword.gif 1KB
nav_changePassword.gif 1KB
addNote.gif 1KB
bg_left_tl.gif 1KB
bg_left_tr.gif 1KB
btn_close.gif 1KB
root_node.gif 1015B
last.gif 899B
first.gif 897B
jump.gif 883B
pre.gif 861B
next.gif 861B
main_hl.gif 803B
minical_btnClose.gif 699B
note.gif 689B
minical_btnForward.gif 644B
minical_btnPrevious.gif 639B
folder_closed.gif 624B
branch_node.gif 605B
bg_button_blue.gif 590B
user_node.gif 583B
main_rc.gif 578B
edit.gif 563B
bg_nav.gif 531B
main_lf.gif 511B
main_rf.gif 511B
bg_th.gif 509B
bg_tr.gif 422B
arrow_collapsed_hover.gif 399B
tree_node.gif 382B
folder_open.gif 381B
arrow_expanded_hover.gif 368B
bg_left_br.gif 316B
bg_left_bl.gif 316B
main_hb.gif 315B
bg_left_tc.gif 255B
bg_header.gif 189B
menu_seprator.gif 176B
bg_tabedbtn.gif 155B
bg_left_bc.gif 148B
bg_left_ls.gif 148B
bg_left_rs.gif 148B
arrow_collapsed.gif 124B
nav_pre.gif 103B
delete.gif 98B
bg_title.gif 93B
main_rs.gif 91B
main_fs.gif 91B
arrow_expanded.gif 91B
main_ls.gif 91B
empty.gif 62B
共 181 条
- 1
- 2
宇宙无敌第一暴龙战士
- 粉丝: 40
- 资源: 34
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- C#微信营销平台源码 微信营销后台管理系统源码数据库 文本存储源码类型 WebForm
- 技术资料分享65C02汇编指令集很好的技术资料.zip
- 课程作业《用51单片机实现的红外人体检测装置》+C语言项目源码+文档说明
- app自动化小白之appium环境安装
- 课程设计-哲学家就餐问题(并发算法问题)-解决策略:资源分级、最多允许四个哲学家同时拿筷子、服务员模式、尝试等待策略
- C#大型公司财务系统源码 企业财务管理系统源码数据库 SQL2008源码类型 WebForm
- MDK文件编译配套工程
- java项目,课程设计-ssm企业人事管理系统ssm.zip
- ton区块链func语言web3智能合约入门课程
- java项目,课程设计-ssm-框架的网上招聘系统的设计与实现
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
前往页