gpt4 book ai didi

java - 如何在jsp页面中显示生成的图像?

转载 作者:太空宇宙 更新时间:2023-11-04 11:48:56 25 4
gpt4 key购买 nike

<%@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 文件所在的位置。这样我就可以在网页中显示它们请帮忙...

最佳答案

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

关于java - 如何在jsp页面中显示生成的图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42050914/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com