package upload;
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.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<String> m_deniedFilesList;
private Vector<String> 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 upload.Files m_files;
private upload.Request 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<String>();
m_allowedFilesList = new Vector<String>();
m_denyPhysicalPath = false;
//m_forcePhysicalPath = false;
m_contentDisposition = ""; //new String();
m_files = new Files();
m_formRequest = new Request();
}
/**
* @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();
}
public final void initialize(ServletContext servletcontext,HttpServletRequest httpservletrequest,HttpServletResponse httpservletresponse) 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)
{
upload.File file = new upload.File();
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,IOException,SmartUploadException
{
return save(s,0);
}
public int save(String s,int i) throws ServletException,IOException,SmartUploadException
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
JavaWeb入门经典实例-共享代码 (127个子文件)
all-wcprops 379B
all-wcprops 371B
all-wcprops 348B
all-wcprops 339B
all-wcprops 83B
SmartUpload.class 16KB
File.class 6KB
StudentService.class 6KB
StudentAddServlet.class 5KB
StudentToEditServlet.class 5KB
BaseDao.class 4KB
StudentListServlet.class 4KB
ServletUpload.class 3KB
StudentInfoBean.class 2KB
Request.class 2KB
ToAddStudentServlet.class 2KB
Files.class 2KB
StudentDeleteServlet.class 2KB
JDBC.class 2KB
StudentEditServlet.class 2KB
DealStr.class 990B
PictureCheck.class 907B
Dao.class 480B
SmartUploadException.class 424B
.classpath 529B
org.eclipse.wst.common.component 489B
org.eclipse.wst.jsdt.ui.superType.container 49B
datepicker.css 4KB
WdatePicker.css 158B
entries 504B
entries 496B
entries 491B
entries 465B
entries 186B
img.gif 2KB
datePicker.gif 1KB
xwork-core-2.1.6.jar 1.49MB
jfreechart-1.0.14.jar 1.39MB
freemarker-2.3.15.jar 859KB
struts2-core-2.1.8.1.jar 738KB
ant.jar 715KB
sqljdbc4.jar 571KB
commons-collections-3.2.jar 558KB
struts2-embeddedjsp-plugin-2.1.8.1.jar 528KB
antlr-2.7.6.jar 433KB
log4j-1.2.14.jar 359KB
antlr-2.7.2.jar 350KB
dom4j-1.6.1.jar 307KB
jcommon-1.0.17.jar 303KB
jtds-1.0.3.jar 276KB
barcode4j.jar 268KB
commons-lang-2.3.jar 240KB
ognl-2.7.3.jar 234KB
commons-beanutils-1.7.0.jar 184KB
jdom.jar 150KB
commons-digester-2.0.jar 145KB
commons-validator-1.3.1.jar 136KB
json-lib-2.1.jar 122KB
commons-io-1.4.jar 106KB
commons-chain-1.2.jar 90KB
barbecue-1.5-beta1.jar 89KB
commons-io-1.3.2.jar 86KB
avalon-framework-4.2.0.jar 84KB
oro-2.0.8.jar 64KB
struts2-convention-plugin-2.1.8.1.jar 60KB
commons-fileupload-1.2.1.jar 56KB
struts2-json-plugin-2.1.8.1.jar 50KB
commons-logging-api-1.1.jar 44KB
commons-logging-1.0.4.jar 37KB
classworlds-1.1.jar 37KB
sslext-1.2-0.jar 26KB
jstl.jar 17KB
json_simple-1.1.jar 16KB
aopalliance-1.0.jar 4KB
SmartUpload.java 26KB
File.java 7KB
StudentService.java 5KB
BaseDao.java 4KB
StudentAddServlet.java 4KB
StudentToEditServlet.java 4KB
StudentListServlet.java 3KB
ServletUpload.java 3KB
Request.java 2KB
StudentEditServlet.java 2KB
StudentInfoBean.java 2KB
JDBC.java 2KB
Files.java 2KB
StudentDeleteServlet.java 1KB
ToAddStudentServlet.java 1KB
PictureCheck.java 789B
DealStr.java 695B
SmartUploadException.java 251B
Dao.java 193B
jquery.js 92KB
calendar.js 21KB
WdatePicker.js 9KB
zh-cn.js 1KB
tool.js 652B
en.js 644B
.jsdtscope 500B
共 127 条
- 1
- 2
ArLUO20
- 粉丝: 33
- 资源: 7
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
- 4
- 5
- 6
前往页