经理安排了一个简单的文件上传并带有进度条的小程序任务,需要结合公司框架完成。
于是小弟从网上找了一个带有进度条的并且用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.如果确实影响到了的话,该如何解决?或者解决的思路是怎么样的。
这是小弟进公司经理安排的第一个小任务,希望各位大神帮忙啊!!!