jsp 페이지에 QR코드 생성

1838 단어 struts2
본고는 온라인에서 QR코드를 생성하는 기능을 소개한다.
사고방식은 검증 코드에 따라 생성된 사고방식을 모방한다.
코드는 다음과 같습니다.
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코드를 생성하는 것이다.

좋은 웹페이지 즐겨찾기