---
title: "struts2显示图片"
author: "yaoweinan"
date: "2010-12-01T15:14:53Z"
tags: []
categories: ["企业架构"]
slug: "struts2"
draft: false
lastmod: "2012-06-04T23:41:47Z"
id: 830502
url: "https://ilyon.iteye.com/blog/830502"
---

import java.io.ByteArrayOutputStream;
import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.opensymphony.xwork2.ActionContext;


public class TestDao {
	private  ByteArrayOutputStream bout = new ByteArrayOutputStream(4096);
public String execute(){
	HttpServletResponse response=(HttpServletResponse)ActionContext.getContext().get(org.apache.struts2.StrutsStatics.HTTP_RESPONSE);
	try {
		
		BarCoderTool barTool=new BarCoderTool();
		bout=barTool.doGet((HttpServletRequest)ActionContext.getContext().get(org.apache.struts2.StrutsStatics.HTTP_REQUEST),(HttpServletResponse)ActionContext.getContext().get(org.apache.struts2.StrutsStatics.HTTP_RESPONSE));
		  }catch (Exception e) {
		// TODO Auto-generated catch block
		//e.printStackTrace();
	} 
		  response.setContentType("image/jpeg");
		  try {
			response.getOutputStream().write(bout.toByteArray());
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	return null;
}
}