package com.jspsmart.upload;
import java.io.*;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Vector;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.PageContext;
// Referenced classes of package com.jspsmart.upload:
// Files, Request, SmartUploadException, File
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 Files m_files;
private 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();
m_allowedFilesList = new Vector();
m_denyPhysicalPath = false;
m_forcePhysicalPath = false;
m_contentDisposition = new String();
m_files = new Files();
m_formRequest = new Request();
}
public final void init(ServletConfig servletconfig) throws ServletException {
m_application = servletconfig.getServletContext();
}
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,
HttpSession httpsession, 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;
long l = 0L;
boolean flag1 = false;
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();
boolean flag2 = false;
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) {
com.jspsmart.upload.File file = new com.jspsmart.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 {
int j = 0;
if (s == null)
s = m_application.getRealPath("/");
if (s.indexOf("/") != -1) {
if (s.charAt(s.length() - 1) != '/')
s = s + "/";
} else if (s.charAt(s.length() - 1) != '\\')
s = s + "\\";
for (int k = 0; k < m_files.getCount(); k++)
if (!m_files.getFile(k).isMissing()) {
m_files.getFile(k).saveAs(s + m_files.getFile(k).getFileName(),
i);
j++;
}
return j;
}
public int getSize() {
return m_totalBytes;
}
public byte getBinaryData(int i) {
byte byte0;
try {
byte0 = m_binArray[i];
} catch (Exception exception) {
throw new ArrayIndexOutOfBoundsException(
"Index out of range (1005).");
}
return byte0;
}
public Files getFiles() {
return m_files;
}
public Request getRequest() {
return m_formRequest;
}
public void downloadFile(String s) throws ServletException, IOException,
SmartUploadException {
downloadFile(s, null, null);
}
public void downloadFile(String s, String s1) throws ServletException,
IOException, SmartUploadException, SmartUploadException {
downloadFile(s, s1, null);
}
public void downloadFile(String s, String s1, String s2)
throws ServletException, IOException, SmartUploadException {
downloadFile(s, s1, s2, 65000);
}
public void downloadFile(String s, String s1, String s2, int i)
throws ServletException, IOException, SmartUploadException {
if (s == null)
throw new IllegalArgumentException("File '" + s
+ "' not found (1040).");
if (s.equals(""))
throw new IllegalArgumentException("File '" + s
+ "' not found (1040).");
if (!isVirtual(s) && m_denyPhysicalPath)
throw new SecurityException("Physical
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
struts2加jquery加Jcrop实现头像剪切上传项目版(添加jar包部署就可以运行) (145个子文件)
all-wcprops 3KB
all-wcprops 1KB
all-wcprops 802B
all-wcprops 350B
all-wcprops 272B
all-wcprops 266B
all-wcprops 242B
all-wcprops 242B
all-wcprops 238B
all-wcprops 101B
all-wcprops 99B
all-wcprops 92B
.classpath 529B
org.eclipse.wst.common.component 468B
org.eclipse.wst.jsdt.ui.superType.container 49B
jquery-ui-1.8.5.custom.css 33KB
jquery.Jcrop.min.css 2KB
entries 3KB
entries 2KB
entries 1KB
entries 559B
entries 422B
entries 420B
entries 414B
entries 393B
entries 393B
entries 273B
entries 240B
entries 236B
SmartUpload.java 18KB
FileUploadAction.java 9KB
File.java 5KB
ImageHepler.java 5KB
Request.java 2KB
Files.java 1KB
LoginFilter.java 978B
PublicConstants.java 522B
SmartUploadException.java 141B
201.jpg 859KB
202.jpg 826KB
205.jpg 763KB
207.jpg 760KB
204.jpg 758KB
208.jpg 606KB
203.jpg 581KB
206.jpg 548KB
110844.jpg 159KB
pool.jpg 38KB
big_1353124809796.jpg 9KB
20090117105013734.jpg 3KB
jquery-ui-1.8.5.custom.min.js 200KB
jquery-1.4.js 155KB
jquery-1.8.3.min.js 91KB
jquery-1.4.2.min.js 71KB
jquery-1.3.2.min.js 56KB
roundabout.js 35KB
jquery.Jcrop.min.js 16KB
corner.js 11KB
ajaxfileupload.js 7KB
roundaboutshapes.js 6KB
.jsdtscope 500B
index.jsp 10KB
demo1.jsp 5KB
MANIFEST.MF 36B
.mymetadata 303B
org.eclipse.wst.jsdt.ui.superType.name 6B
ui-icons_e0fdff_256x240.png 5KB
ui-icons_fcd113_256x240.png 4KB
ui-icons_f5e175_256x240.png 4KB
ui-icons_0078ae_256x240.png 4KB
ui-icons_d8e7f3_256x240.png 4KB
ui-icons_f7a50d_256x240.png 4KB
ui-icons_056b93_256x240.png 4KB
ui-bg_flat_55_999999_40x100.png 180B
ui-bg_highlight-hard_50_6eac2c_1x100.png 166B
ui-bg_highlight-soft_55_f8da4e_1x100.png 131B
ui-bg_inset-hard_75_2191c0_1x100.png 125B
ui-bg_highlight-hard_75_79c9ec_1x100.png 124B
ui-bg_highlight-hard_45_e14f1c_1x100.png 121B
ui-bg_inset-hard_45_0078ae_1x100.png 120B
ui-bg_inset-hard_75_aaaaaa_1x100.png 105B
ui-bg_highlight-hard_100_fcfdfd_1x100.png 88B
org.eclipse.jdt.core.prefs 395B
org.eclipse.core.resources.prefs 88B
.project 2KB
jquery-ui-1.8.5.custom.min.js.svn-base 200KB
jquery-1.4.2.min.js.svn-base 71KB
jquery-ui-1.8.5.custom.css.svn-base 33KB
SmartUpload.java.svn-base 18KB
jquery.Jcrop.min.js.svn-base 16KB
dtree2.js.svn-base 13KB
dtree.js.svn-base 12KB
FileUploadAction.java.svn-base 9KB
big_1353124809796.jpg.svn-base 9KB
ajaxfileupload.js.svn-base 7KB
File.java.svn-base 5KB
ui-icons_e0fdff_256x240.png.svn-base 5KB
BQUtils.js.svn-base 5KB
ImageHepler.java.svn-base 5KB
ui-icons_fcd113_256x240.png.svn-base 4KB
共 145 条
- 1
- 2
梦想秀
- 粉丝: 1
- 资源: 3
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
前往页