起步软件技术论坛
搜索
 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 1748|回复: 4

[处理中3] 获取数据库图片后为什么在页面上显示不出来?

[复制链接]

135

主题

387

帖子

775

积分

高级会员

Rank: 4

积分
775
QQ
发表于 2018-3-21 16:43:55 | 显示全部楼层 |阅读模式
获取路径方式如图 2.png 1.png 3.png

135

主题

387

帖子

775

积分

高级会员

Rank: 4

积分
775
QQ
 楼主| 发表于 2018-3-21 16:44:27 | 显示全部楼层
bass端代码:// 获取图纸
        public static JSONObject getImgInfo(JSONObject params, ActionContext context) throws JsonGenerationException, JsonMappingException, IOException {
                String id = params.getString("id"); // 获取图纸ID
                System.out.println("//////////////////////////////////////////");
                HttpServletRequest request = (HttpServletRequest) context.get(ActionContext.REQUEST);
                HttpServletResponse response = (HttpServletResponse) context.get(ActionContext.RESPONSE);

                PreparedStatement pstmt = null;
                ResultSet rs = null;
                Connection conn = null;
                String sql = "";
                JSONObject result = new JSONObject();
                try {
                        conn = context.getConnection("txxt");
                        if (id != null) {
                                sql = "SELECT * FROM ENTITY_000 WHERE ID = '" + id + "' AND USED = 1;";
                                System.out.println(sql);
                                pstmt = conn.prepareStatement(sql);
                                rs = pstmt.executeQuery();
                                if (rs != null) {
                                        if (rs.next()) {
                                                String imgUrlExt = rs.getString("EXT");
                                                Blob blob = rs.getBlob("ENTITY");
                                                InputStream ins = blob.getBinaryStream();
                                                result.put("imgUrlExt", imgUrlExt);
                                                System.out.println(imgUrlExt);
                                                 String file = null;
                                                // 输出到文件
                                                 OutputStream fout = new FileOutputStream(file);
                                                 // 下面将BLOB数据写入文件
                                                 byte[] b = new byte[1024];
                                                 int len = 0;
                                                 while ((len = ins.read(b)) != -1) {
                                                 fout.write(b, 0, len);
                                                 }

                                                response.setContentType("DWG/WMF");
                                                response.setHeader("Cache-control", "no-cache");

                                                ServletOutputStream fout1 = response.getOutputStream();

                                                int num;
                                                byte buf[] = new byte[1024];
                                                while ((num = ins.read(buf)) != -1) {
                                                        fout1.write(buf, 0, num);
                                                }

                                                // 依次关闭
                                                fout.close();
                                                ins.close();
                                        }
                                }
                        }
                } catch (Exception e) {
                        e.printStackTrace();
                } finally {
                        try {
                                conn.close();
                        } catch (Exception e2) {
                                e2.printStackTrace();
                        }
                }
                return result;
        }
回复 支持 反对

使用道具 举报

135

主题

387

帖子

775

积分

高级会员

Rank: 4

积分
775
QQ
 楼主| 发表于 2018-3-21 16:45:28 | 显示全部楼层
控制台报错信息 4.png
回复 支持 反对

使用道具 举报

发表于 2018-3-27 14:04:16 | 显示全部楼层
java 打断点调试跟下代码吧!
第一句
String id = params.getString("id"); // 获取图纸ID
就有问题吧, 你不是按 标准的 baas 请求API 发送请求的,参数使用的是get请求参数
怎么可以从params 中得到参数的值呢??

从request 中获取参数试试,另外就是 断点调试java 是否执行都满足预期的?

qq:1912779713
WeX5教程--WeX5下载
回复 支持 反对

使用道具 举报

135

主题

387

帖子

775

积分

高级会员

Rank: 4

积分
775
QQ
 楼主| 发表于 2018-4-9 14:13:52 | 显示全部楼层
liangyongfei 发表于 2018-3-27 14:04
java 打断点调试跟下代码吧!
第一句
String id = params.getString("id"); // 获取图纸ID

具体该如何获取参数呢,您能不能给个例子或者一段代码?
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|X3技术论坛|Justep Inc.    

GMT+8, 2024-9-27 19:19 , Processed in 0.112131 second(s), 26 queries .

Powered by Discuz! X3.4

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表