jsp向页面显示图片,找不到文件时直接使用java画图
来源:互联网 发布:炉石传说盒子 mac 3.0 编辑:程序博客网 时间:2024/06/08 03:27
protected void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException {String imgId = request.getParameter("fileId");TSysMapService tsysMapService = (TSysMapService) Framework.getEngine().getContainer().getComponent("tsysMapService");// 鍥剧墖SERVICETSysMap image = tsysMapService.getTSysMapById(imgId);// String// fileFullPath=image.getFilePath()+File.separator+image.getFileName();File file = new File(image.getFilePath());FileInputStream input = null;if (file.exists()) {try {input = new FileInputStream(image.getFilePath());String contentType = "image/*";int i = input.available();byte[] data = new byte[i];input.read(data);input.close();response.setContentType(contentType);OutputStream outStream = response.getOutputStream();outStream.write(data);outStream.close();} catch (Exception e) {e.printStackTrace();PrintWriter out = response.getWriter();out.println("图片无法打开");out.close();}} else {BufferedImage buffer = new BufferedImage(100, 80,BufferedImage.TYPE_INT_RGB);Graphics2D g2 = buffer.createGraphics();Font font = new Font("宋体", Font.BOLD, 12);g2.setFont(font);// actually do the drawingg2.setColor(Color.gray);g2.fillRect(0, 0, 100, 80);g2.setColor(Color.BLACK);g2.drawString("找不到图片", 10, 30);// set the content type and get the output streamresponse.setContentType("image/png");OutputStream os = response.getOutputStream();// output the image as pngImageIO.write(buffer, "png", os);os.close();}}
参考:Generating Images with JSPs and Servlets
- jsp向页面显示图片,找不到文件时直接使用java画图
- JSP页面直接显示Blob类型图片
- 通过Java向JSP页面生成图片
- JFreeChart画图+jsp页面显示
- JFreeChart画图+jsp页面显示
- jsp页面直接显示excel
- JSP页面使用文件上传图片并且回传显示的注意事项
- 将文件中的图片显示到jsp页面
- jsp页面如何显示图片
- 图片显示到jsp页面
- jsp页面操作图片显示
- jsp图片上传到数据库里面之后,不能直接在页面上显示,而是提示下载
- servlet使用dispatcher转jsp页面,原本图片无法显示
- Jsp页面图片img标签使用绝对路径进行显示
- java byte[] 转图片 在jsp页面显示
- jsp页面通过java调用oracle blob字段显示图片
- java中图片上传并在jsp页面显示
- java byte[] 转图片 在jsp页面显示
- 【手册】向原生XPages说byebye,安装并配置XPages Extension Library
- 建立远程仓库2
- 字符串旋转算法 -- 求逆
- poj 3637 Shopaholic
- 【Android API指南】动画和图像(5) - OpenGL
- jsp向页面显示图片,找不到文件时直接使用java画图
- ios与Android的优劣
- 1.Strut国际化动态文本(声明式处理异常,可以拥有多个占位符):界面
- 对面向对象程序设计三大特征的理解
- [Web] 反向代理
- Wireshark 远程抓包 .
- linux下MySQL安装及设置
- 2.Strut国际化动态文本(声明式处理异常,可以拥有多个占位符):ActionForm
- 3.Strut国际化动态文本(声明式处理异常,可以拥有多个占位符):Action