|
楼主 |
发表于 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;
} |
|