【问题标题】:how to display generated images in jsp page?如何在jsp页面中显示生成的图像?
【发布时间】:2017-02-05 10:24:51
【问题描述】:
<%@page import="com.google.zxing.client.j2se.MatrixToImageWriter"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>JSP Page</title>
</head>

    <h1>Hello World!</h1>
    <%@page language='java'%>
    <%@page import="java.io.*,java.util.*,java.util.Hashtable,javax.imageio.*,com.google.zxing.*,com.google.zxing.client.*,com.google.zxing.common.*,com.google.zxing.qrcode.decoder.*"%>
     <% 
    String qrCodeData = "Hello World!";
    String filePath = "QRCode.png";
    String charset = "UTF-8"; // or "ISO-8859-1"
    Hashtable hintMap = new Hashtable();
    hintMap.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.L);

    createQRCode(qrCodeData, filePath, charset, hintMap, 200, 200);
    out.println("QR Code image created successfully!");

%>      
<%!

public void createQRCode(String qrCodeData, String filePath,
        String charset,Hashtable hintMap, int qrCodeheight, int qrCodewidth)
        throws WriterException, IOException {
    BitMatrix matrix = new MultiFormatWriter().encode(
            new String(qrCodeData.getBytes(charset), charset),
            BarcodeFormat.QR_CODE, qrCodewidth, qrCodeheight,hintMap);
    MatrixToImageWriter.writeToFile(matrix, filePath.substring(filePath
            .lastIndexOf('.') + 1), new File(filePath));
}




        %>

</body>
</html>

此代码在 tomcat\bin 目录中生成 QR 图像。我想将目录更改为 jsp 文件所在的位置。这样我就可以在网页中显示它们 请帮忙...

【问题讨论】:

    标签: java html jsp qr-code


    【解决方案1】:

    我做了一个生成 qrcode 而不保存它的例子。看到这个答案: Display dynamically generated image to the browser using jsp

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-09-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-09-29
      • 1970-01-01
      • 2011-04-13
      相关资源
      最近更新 更多