package smartupload;
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)
{
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 = 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;
}
}
}
public int save(String s) throws ServletException,IOExcepti
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
基于SSM航空票务系统 (340个子文件)
SmartUpload.class 16KB
UserController.class 14KB
QuestionController.class 11KB
DaoSupportImpl.class 7KB
QuestionServiceImpl.class 7KB
SmartFile.class 6KB
PaperServiceImpl.class 5KB
PaperController.class 4KB
UserServiceImpl.class 4KB
OptionController.class 4KB
PageUtil.class 3KB
ExcelUtil.class 3KB
Common.class 3KB
DBConn.class 3KB
UserAnswerController.class 3KB
User.class 3KB
Paper.class 2KB
Question.class 2KB
LoginInterceptor.class 2KB
SysConstants.class 2KB
LoginInfoListener.class 2KB
SystemLogServiceImpl.class 2KB
PageBean.class 2KB
SmartRequest.class 2KB
SysConstants$ReturnMessage.class 2KB
MyDateUtil.class 2KB
SmartFiles.class 2KB
SystemLogController.class 2KB
SystemLog.class 2KB
UserAnswer.class 1KB
RandomUtil.class 1KB
Option.class 1KB
UserAnswerServiceImpl.class 1KB
OptionServiceImpl.class 1KB
IdGenerator.class 1KB
RoleController.class 1KB
DaoSupport.class 1KB
TestOption.class 1KB
HqlMaker.class 1018B
MyStringUtil.class 979B
Role.class 949B
Test.class 794B
ExcelError.class 755B
SysConstants$Paper.class 733B
QuestionService.class 634B
RoleServiceImpl.class 589B
IdGendertor.class 570B
PaperService.class 536B
UserService.class 532B
SysConstants$Question.class 520B
ConditionMap.class 448B
SmartUploadException.class 370B
SysConstants$User.class 353B
UserAnswerService.class 342B
SysConstants$Option.class 327B
OptionService.class 326B
SystemLogService.class 321B
SysConstants$Role.class 311B
SysConstants$UserAnswer.class 286B
RoleService.class 227B
.classpath 1KB
org.eclipse.wst.common.component 567B
org.eclipse.wst.jsdt.ui.superType.container 49B
css.css 315B
poi-ooxml-schemas-3.9-20121203.jar 4.58MB
hibernate3.jar 3.97MB
xmlbeans-2.6.0.jar 2.6MB
poi-3.9-20121203.jar 1.78MB
com.springsource.org.aspectj.weaver-1.6.8.RELEASE.jar 1.57MB
poi-scratchpad-3.9-20121203.jar 1.17MB
poi-ooxml-3.9-20121203.jar 915KB
freemarker-2.3.19.jar 909KB
spring-core-3.2.0.RELEASE.jar 843KB
spring-context-3.2.0.RELEASE.jar 834KB
mysql-connector-java-5.1.12-bin.jar 716KB
mysql-connector-java-5.1.12-bin.jar 716KB
mysql-connector-java-5.1.5-bin.jar 661KB
spring-webmvc-3.2.0.RELEASE.jar 621KB
javassist-3.12.0.GA.jar 618KB
spring-web-3.2.0.RELEASE.jar 610KB
com.springsource.com.mchange.v2.c3p0-0.9.1.2.jar 603KB
spring-beans-3.2.0.RELEASE.jar 591KB
commons-collections-3.1.jar 546KB
log4j-1.2.16.jar 470KB
antlr-2.7.6.jar 433KB
spring-jdbc-3.2.0.RELEASE.jar 392KB
com.springsource.org.apache.log4j-1.2.15.jar 387KB
standard.jar 384KB
spring-orm-3.2.0.RELEASE.jar 383KB
spring-aop-3.2.0.RELEASE.jar 327KB
backport-util-concurrent.jar 320KB
commons-lang3-3.1.jar 308KB
dom4j-1.6.1.jar 307KB
poi-examples-3.9-20121203.jar 302KB
ehcache-1.5.0.jar 258KB
commons-lang.jar 237KB
spring-tx-3.2.0.RELEASE.jar 235KB
ognl-3.0.5.jar 222KB
spring-expression-3.2.0.RELEASE.jar 189KB
commons-beanutils.jar 184KB
共 340 条
- 1
- 2
- 3
- 4
资源评论
- 用你的微笑_做一枚书签2019-05-11刚才在,还没测试,文件比较全
- 奋斗的新丁2019-06-22没有数据库文件,而且!这是个考试系统
slqslqslqs
- 粉丝: 0
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功