Current Position:Home > Barcode Image display in email/jsp

Barcode Image display in email/jsp

Update:11-30Source: network consolidation
Advertisement
Hi,
I want to display the barcode image in the email/jsp.
I have created one droplet. This will generate the barcode image and will return as a OutputStream.
I am trying to convert this OutputStream as a byte array and setting in a request param. When i access this param in the jsp and trying to display as a image using dsp:valueof or dsp:img tag, i am getting only the byte array whatever i have set in the droplet instead of image.
I have set the content type as image/jpeg also in the request object.
I have tried to write the converted byte array in a response object also and accessed the droplet in jsp.
But i am not getting the image in the jsp. I am getting only the byte array in the jsp.
Please suggest me any other solution to resolve this.
Thanks,
Saravanan

The Best Answer

Advertisement
If you have a binary array for image, you can try to use a servlet for rendering the image directly from the byte array. Doing it through a separate servlet would ensure that we do not run into the issue of mixing character and binary based response streams. Here is the pseudo code for doing this.
In Servlet:
BarcodeImageHandlerServlet extends extends HttpServletService {
public void service(HttpServletRequest request, HttpServletResponse response)  throws ServletException, IOException {
  byte [] imageByteArr = getImage(); //your image byte array
  String name= "barcode-01";
  response.setContentType("image/jpeg");
  response.setContentLength(imageByteArr.length);
  response.setHeader("Content-Disposition", "inline; filename=\"" + name + "\"");
  BufferedInputStream input = null;
  BufferedOutputStream output = null;
  try {
    input = new BufferedInputStream(new ByteArrayInputStream(imageByteArr));
    output = new BufferedOutputStream(response.getOutputStream());
    output.write(imageByteArr);
  catch (IOException e) {
  finally {
    if (output != null) {
      try {
        output.close();
      catch (IOException iex) {
    if (input != null) {
      try {
        input.close();
      catch (IOException iex) {
}Create following component configurations in your application's config layer to add your servlet using ServletPathServlet and ServletPathDispatcher:
/atg/myapp/BarcodeImageServlet.properties:
$class=com.myapp.BarcodeImageHandlerServlet
$scope=global
/atg/dynamo/servlet/pipeline/ServletPathDispatcher.properties:
dispatcherServiceMap+=\
/barcode-image-servlet\=/atg/myapp/BarcodeImageServlet
/atg/dynamo/servlet/pipeline/ServletPathServlet.properties:
servletPaths+=/barcode-image-servlet
Then in your JSP you can call it as:
<img src="<c:out value="${pageContext.request.contextPath}"/>/dyn/barcode-image-servlet" />

Recommended Content

  • My firefox doen't open with a normal screen but with all icons and topics showing as bullits on my screen
  • My daughters iPod touch 4th gen has been disabled from her locking it with a password,forgetting the password,and now it says disabled connect to iTunes .  The problem is the computer it was set up on is no longer operational.
  • Bonjour/Rendezvous support under OS 9
  • HT201250 After Time Machine has backed up my files, can I delete my originals from my Mac and do something in Time Machine to ensure it will never automatically delete them from the backup in the future?
  • Best practice to securely format a solid state hard drive.
  • Adobe Document Services Error : 405 - Method Not Allowed
  • Implicit Fact Column - am I thinking about this the right way?
  • Can I Use Singletone  Pattren for DAO in Stateless EJB?
  • Known issue: BackgroundTransfer sample fails with 0x80070002 error when using Windows Phone Emulator (Windows 10 Insider Preview SDK and tools, April 2015 release)
  • Best practice of KM development project setup
  • Scheduling of BW Reports in background - download to predef folders
  • I have iphone 5 can i change it from apple and pay the difference bettween both value
  • How to see WAD reports on browser
  • When i open .jpg picture in photoshop on MAC the the background thumbnail in the layers panel looks like a white box with the brush inside instead of picture thumbnail. how to fix it?
  • TS3212 running windows 7 64 bit home premium edition, getting installer error when attempting to download itunes