java 下载

来源:互联网 发布:淘宝管控记录怎么撤销 编辑:程序博客网 时间:2024/04/30 10:24
    private static final String SQL_QUERY_MAP="select resname,contenttype,downtimes from courseresource where resid=?";
    
public Map getResourceInfo(int resid) {
        Map i
=jt.queryForMap(SQL_QUERY_MAP,new Object[]{Integer.valueOf(resid)});
        
return i;
    }

    
private static final String SQL_DOWNTIMES_UP="update courseresource set downtimes=? where resid=?";
    
public void addDownTimes(long downTimes, int resid) {
        
long downtime=downTimes+1;
        jt.update(SQL_DOWNTIMES_UP,
new Object[]{downtime,resid});
    }






private InputStream inputStream;
    
private String resFileContentType;
    
    
    
public InputStream getInputStream() {
        
return inputStream;
    }


    
public void setInputStream(InputStream inputStream) {
        
this.inputStream = inputStream;
    }


    
public String getResFileContentType() {
        
return resFileContentType;
    }


    
public void setResFileContentType(String resFileContentType) {
        
this.resFileContentType = resFileContentType;
    }


    
public String download() throws Exception {
        
long downTimes;
        
try {
            Map res 
= getServMgr().getCourseResourceService().getResourceInfo(resid);
            inputStream 
= new FileInputStream(ServletActionContext
                    .getServletContext().getRealPath(
                            
"/WEB-INF/files/courseResource/" + resid + "."+(String) res.get("CONTENTTYPE")));
            resFileFileName 
= URLEncoder.encode((String) res.get("RESNAME"),
                    
"UTF-8");
            log.debug(
"--------------------resFileFileName-----------------------"+resFileFileName);
            resFileContentType 
= (String) res.get("CONTENTTYPE");
            downTimes 
= Integer.parseInt(String.valueOf(res.get("DOWNTIMES")));
        }
 catch (FileNotFoundException e) {
            setResult(ERROR);
            addMessage(
"下载的文件不存在!");
            addRedirURL(
"关闭窗口""javascript:window.close()");
            
return EXECUTE_RESULT;
        }


        getServMgr().getCourseResourceService().addDownTimes(downTimes, resid);
        
return SUCCESS;
    }



 
原创粉丝点击