经理安排了一个简单的文件上传并带有进度条的小程序任务,需要结合公司框架完成。
于是小弟从网上找了一个带有进度条的并且用smartupload组件做的上传组件的例子(小弟刚出校园,进度条确实不晓得怎么做)
但是小弟在做这个小程序的过程中发现,只要和公司的框架结合就会出现读取到的上传文件是-1的情况。经理他从网上查到的资料中也了解到smartupload如果用了经过包装的request的确是会出现读取文件-1的问题,但是他最近业务繁忙,他希望我自己能把这个问题解决,如果实在不行就换上传组件。HttpRequest V_HttpRequest = new HttpRequest(request, response);//HttpRequest这个类是公司提供并且经过封装的,实际上getParameter("caozuo")是取不到值的
String pageErrorInfo = null;
SmartUpload su = null;
try{
su = new SmartUpload();
su.initialize(pageContext);
su.upload();
//String filepath = SysEnv.getFileRoot()+su.getRequest().getParameter("path")+"\\";
String filepath = "G:\\up\\";
System.out.println("ddddddd"+filepath);
pageErrorInfo = PhotoMgr.fileUpload(filepath,su,pageContext);
if(pageErrorInfo==null){
out.print("successed");
}
}catch(Exception e){
pageErrorInfo = e.getMessage();
}finally{
su = null;
if(pageErrorInfo!=null){
out.print(pageErrorInfo);
}
}//这是smartupload类中的upload()方法的部分源码
public void upload()
throws SmartUploadException, IOException, ServletException
{
int totalRead = 0;
int readBytes = 0;
long totalFileSize = 0L;
boolean found = false;
String dataHeader = new String();
String fieldName = new String();
String fileName = new String();
String fileExt = new String();
String filePathName = new String();
String contentType = new String();
String contentDisp = new String();
String typeMIME = new String();
String subTypeMIME = new String();
boolean isFile = false;
m_totalBytes = m_request.getContentLength();
m_binArray = new byte[m_totalBytes];
for(; totalRead < m_totalBytes; totalRead += readBytes)
try
{
//m_request.getInputStream();
readBytes = m_request.getInputStream().read(m_binArray, totalRead, m_totalBytes - totalRead);//(如果和公司框架结合)执行到这句话的时候,readBytes=-1 也就是无限循环。
}
catch(Exception e)
{
throw new SmartUploadException("Unable to upload.");
}.......
小弟的疑问是,
1.经理说是因为smartupload用了公司封装后的request,但是小弟认为smartupload组件是靠
su.initialize(pageContext);接收request对象的。
公司的HttpRequest V_HttpRequest = new HttpRequest(request, response);
又没有将pageContext里的request包装了,怎么会影响到smartupload组件里接收的request呢?
2.如果确实影响到了的话,该如何解决?或者解决的思路是怎么样的。
这是小弟进公司经理安排的第一个小任务,希望各位大神帮忙啊!!!
于是小弟从网上找了一个带有进度条的并且用smartupload组件做的上传组件的例子(小弟刚出校园,进度条确实不晓得怎么做)
但是小弟在做这个小程序的过程中发现,只要和公司的框架结合就会出现读取到的上传文件是-1的情况。经理他从网上查到的资料中也了解到smartupload如果用了经过包装的request的确是会出现读取文件-1的问题,但是他最近业务繁忙,他希望我自己能把这个问题解决,如果实在不行就换上传组件。HttpRequest V_HttpRequest = new HttpRequest(request, response);//HttpRequest这个类是公司提供并且经过封装的,实际上getParameter("caozuo")是取不到值的
String pageErrorInfo = null;
SmartUpload su = null;
try{
su = new SmartUpload();
su.initialize(pageContext);
su.upload();
//String filepath = SysEnv.getFileRoot()+su.getRequest().getParameter("path")+"\\";
String filepath = "G:\\up\\";
System.out.println("ddddddd"+filepath);
pageErrorInfo = PhotoMgr.fileUpload(filepath,su,pageContext);
if(pageErrorInfo==null){
out.print("successed");
}
}catch(Exception e){
pageErrorInfo = e.getMessage();
}finally{
su = null;
if(pageErrorInfo!=null){
out.print(pageErrorInfo);
}
}//这是smartupload类中的upload()方法的部分源码
public void upload()
throws SmartUploadException, IOException, ServletException
{
int totalRead = 0;
int readBytes = 0;
long totalFileSize = 0L;
boolean found = false;
String dataHeader = new String();
String fieldName = new String();
String fileName = new String();
String fileExt = new String();
String filePathName = new String();
String contentType = new String();
String contentDisp = new String();
String typeMIME = new String();
String subTypeMIME = new String();
boolean isFile = false;
m_totalBytes = m_request.getContentLength();
m_binArray = new byte[m_totalBytes];
for(; totalRead < m_totalBytes; totalRead += readBytes)
try
{
//m_request.getInputStream();
readBytes = m_request.getInputStream().read(m_binArray, totalRead, m_totalBytes - totalRead);//(如果和公司框架结合)执行到这句话的时候,readBytes=-1 也就是无限循环。
}
catch(Exception e)
{
throw new SmartUploadException("Unable to upload.");
}.......
小弟的疑问是,
1.经理说是因为smartupload用了公司封装后的request,但是小弟认为smartupload组件是靠
su.initialize(pageContext);接收request对象的。
公司的HttpRequest V_HttpRequest = new HttpRequest(request, response);
又没有将pageContext里的request包装了,怎么会影响到smartupload组件里接收的request呢?
2.如果确实影响到了的话,该如何解决?或者解决的思路是怎么样的。
这是小弟进公司经理安排的第一个小任务,希望各位大神帮忙啊!!!
解决方案 »
- javaweb项目,怎样实现封装成exe程序直接运行安装
- iReport自己添加饼状图
- ServletContext对象和jsp中的作用域对象有什么联系?
- struts中 实用bean:message 中文乱码的问题
- 求助使用jmesa的时候不能翻页了
- 各位大虾:我们有一个项目需要使用连接池,我写了一个连接池但使用连接池后会造成applet频繁无法找到,搞不清什么原因,请教高手
- 求一个详细的可以运行的基于SSH的办公用品网上商城详细源码
- "一个关于数据查询的程序,常编程的过来看看,"!!!!UP有分 。。。。。。在线等!!!!!!!!!!
- 我用websphere,怎么没有servlet.http这个包啊.
- 初学者的 Servlet 和JSP 软件的配置和安装问题
- 遇到了一个关于timestamp的问题。
- 复选框问题!!!求指点
还不晓得wen题到底出在哪。
还在debug 给的那个jar包