response打印字节和字符串的方法区别

来源:互联网 发布:生产网络拓扑图 编辑:程序博客网 时间:2024/06/10 17:49

response打印字节和字符串的方法区别

 

 

@RequestMapping(value = "/account/tbCusFirmChg/showImage")

    public void showReportImage(@RequestParam(value = "path") String path,

                                HttpServletRequest request,HttpServletResponse response) throws IOException, NumberFormatException, EsteelException {

//             response.setContentType("image/jpeg");

 

            response.setCharacterEncoding("UTF-8");

//        String filePath= WebConfig.get("filePath");

            String pathBase = StaticVariables.Base_Path;

        File file=null;

        if(path!=null&&!"".equals(path)){

            file=new File(pathBase+path);

        }

        if( file==null||!file.exists()){

                response.getWriter().print("未找到图片");/////////////打印普通字符

        }else {

            response.setContentType("image/jpeg");

            FileInputStream fos = new FileInputStream(file);

            byte[] bytes = new byte[1024*1024];

            int length = 0;

            while((length=fos.read(bytes))!=-1){

                response.getOutputStream().write(bytes,0,length);///打印流

            }

        }

    }

 

0 0
原创粉丝点击