图像标记仅在chrome中不起作用

时间:2017-04-15 10:10:21

标签: java image jsp barcode

img标签未在Chrome上显示,但在IE和Firefox上正常运行 这些是JSP页面:

try {

    response.setContentType("image/jpeg");
    Linear barcode = new Linear();
    barcode.setType(Linear.CODE11);
    barcode.setData("12345678912");
    barcode.setUOM(Linear.UOM_PIXEL);
    barcode.setX(3f);
    barcode.setY(75f);
    barcode.setLeftMargin(0f);
    barcode.setRightMargin(0f);
    barcode.setTopMargin(0f);
    barcode.setBottomMargin(0f);
    barcode.setResolution(72);
    barcode.setShowText(true);
    barcode.setTextFont(new Font("Arial", 0, 12));
    barcode.setRotate(Linear.ANGLE_0);
    File bimg = new File(barcode.getData());
    System.out.println(bimg.length());
    ImageIO.write(barcode.renderBarcode(), "jpeg", response.getOutputStream());
} catch (Exception e) {
    System.out.println(e);
}

%GT;

getbarcode.jsp
<img id="images" height="100px" width="300px" src="barcodecode.jsp">

我正在使用chrom版本57.0.2987.133(64位)和NetBean 8.0.2

1 个答案:

答案 0 :(得分:0)

我得到了解决方案: 我刚补充......

<%@page autoFlush="false" contentType="image/jpeg" %>

在我的barcode.jsp页面中并替换

ImageIO.write(barcode.renderBarcode(), "jpeg", response.getOutputStream());

barcode.renderBarcode(response.getOutputStream());