ITeye博客

struts2显示图片

yaoweinan · 2010-12-01 15:14 · struts · 企业架构 · Markdown

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;

} }

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。