解决方案 »

  1.   

    1:这种设置常量的思维是否正确,项目中是否就是这么处理的呢?
    可以这么处理,上传的附件,诸如图片一般都是另辟空间存储的
    2:当上传的时候可以把文件上传到设置的常量路径里面,但是客户端怎么才能读取到服务器里面【/opt/upload/】下对应的文件并且显示呢?
    文件上传到指定的目录后,将目录名称和文件名存储在数据库中,读取时,按照数据库的目录和文件名来读取附件,然后通过输出流的方式给到前台就可以了
      

  2.   


    是的。现在也是这样配置的。但是现在的情况是用输出流也不能显示,请帮忙看一下,谢谢!jsp:
    <img src="${path }/main/enocp/train/plan/showImage.do" alt=""/>controller:
    @RequestMapping("showImage")
        public void showImage(HttpServletRequest re,HttpServletResponse response,String pic_addr){
    response.setContentType("image/*");   
            FileInputStream fis = null; 
            OutputStream os = null;
    pic_addr = cacheService.queryParam("ENOCP_SAVE_FILE")+File.separator+"Chrysanthemum.jpg";
            try {
             fis = new FileInputStream(new File(pic_addr));
             os = response.getOutputStream();
                int count = 0;
                byte[] buffer = new byte[1024];
                while ( (count = fis.read(buffer)) != -1 ){
                 os.write(buffer, 0, count);
                 os.flush();
                }
            }catch(Exception e){
             e.printStackTrace();
            }finally {
                try {
    fis.close();
    os.close();
    } catch (IOException e) {
    e.printStackTrace();
    }
            }方法是确定进来了的。就是页面显示不成功,直接一个红叉叉!
      

  3.   

    这是之前我写的一个app客户端接口,用于上传图片,供参考
    MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
    // 上传路劲,获取项目存放绝对地址
    String uploadPath = request.getSession().getServletContext()
    .getRealPath("/")
    + "upload/image/";
    // 获取上传的图片
    MultipartFile areaPicture = multipartRequest.getFile("picture");
    if (!areaPicture.isEmpty()) {
    fileName = areaPicture.getOriginalFilename();//获取图片名,可保存到数据库中
    byte[] fileData = areaPicture.getBytes();
    String filePathStr = uploadPath + fileName;//保存地址
    IoUtil.TurnFile(fileData, filePathStr);//保存图片方法
    }public class IoUtil {

    public static  boolean TurnFile(byte[] fileData, String path) {
    try {

    for (int i = 0; i < fileData.length; ++i) {
    if (fileData[i] < 0) {// 调整异常数据
    fileData[i] += 256;
    }
    }
    // 生成jpeg图片
    OutputStream out = new FileOutputStream(path);
    out.write(fileData);
    out.flush();
    out.close();
    return true;
    } catch (Exception e) {
    e.printStackTrace();
    return false;
    } }图片可以通过链接获取
      

  4.   

    引用..
    http://57share.net/portal.php?mod=list&catid=8