jsp 페이지에 QR코드 생성
1838 단어 struts2
사고방식은 검증 코드에 따라 생성된 사고방식을 모방한다.
코드는 다음과 같습니다.
package com.sys.productNew.action;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.OutputStream;
import javax.imageio.ImageIO;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts2.ServletActionContext;
import com.huchi.util.qrutils.PictureUtils;
import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionSupport;
public class ProductNewAction extends ActionSupport {
//
private String productId;
//
public String prevQRPicture() throws IOException {
return Action.SUCCESS;
}
//
public void QRPicture() {
HttpServletResponse response=ServletActionContext.getResponse();
response.setDateHeader("Expires", 0);
response.setHeader("Cache-Control", "no-cache");
response.setHeader("Pragma", "No-cache");
response.setContentType("image/jpeg");
//
String url = "http://xx/yy/zz.action?productId=";
BufferedImage image = PictureUtils.generateQRCode(url + productId);
OutputStream os = null;
try {
os = response.getOutputStream();
ImageIO.write(image, "JPEG", os);
} catch (IOException e) {
e.printStackTrace();
} finally {
if (os != null) {
try {
os.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
public String getProductId() {
return productId;
}
public void setProductId(String productId) {
this.productId = productId;
}
}
HTML :
이 기능은 QR코드를 흐르는 방식으로 JSP 페이지에 쓸 수 있다.주의해야 할 것은 의 src기능을 통해 액션에 접근하는 방법을 통해 흐르는 방식으로 QR코드를 생성하는 것이다.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
한 편의 문장으로 Struts2의 유형 전환을 해결하다우리는 HTTP를 통해 백그라운드에 제출된 데이터가 모두 문자열의 형식이라는 것을 알고 있으며, 우리가 필요로 하는 데이터 형식은 당연히 문자열 형식 하나만 있는 것이 아니다.그래서 우리는 유형 전환이 필요하다!다음...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.