Display buffered image on JSP

Only JSP

<%

BufferedImage bImage = ImageIO.read(new File(“/home/mohit/Desktop/mohit.jpg”));//give the path of an image
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageIO.write( bImage, “jpg”, baos );
baos.flush();
byte[] imageInByteArray = baos.toByteArray();
baos.close();
String b64 = javax.xml.bind.DatatypeConverter.printBase64Binary(imageInByteArray);

%>

<img src=”data:image/jpg;base64, <%=b64%>” alt=”Image not found” />

When buffered image is passed to JSP as session attribute

Servlet

request.getSession().setAttribute(“bufferedimage”, bufferedimage);

JSP

<%

BufferedImage bImage =  (BufferedImage) session.getAttribute(“bufferedimage”);

ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageIO.write( bImage, “jpg”, baos );
baos.flush();
byte[] imageInByteArray = baos.toByteArray();
baos.close();
String b64 = javax.xml.bind.DatatypeConverter.printBase64Binary(imageInByteArray);

%>

<img src=”data:image/jpg;base64, <%=b64%>” alt=”Image not found” />

When buffered image stream is passed to JSP as session attribute

Servlet

ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageIO.write(bufferedimage, “jpg”, baos );
baos.flush();
byte[] imageInByteArray = baos.toByteArray();
baos.close();
String b64 = javax.xml.bind.DatatypeConverter.printBase64Binary(imageInByteArray);
request.getSession().setAttribute(“b64”, b64);

JSP

<img src=”data:image/jpg;base64, <%=b64%>” alt=”Image not found” />

Enable eclipse debug for weblogic server

Set following code in bat file used to start weblogic server:

set JAVA_OPTIONS=-Dweblogic.j2ee.application.tmpDir=c:/temp %JAVA_OPTIONS%

set JAVA_OPTIONS= %JAVA_OPTIONS% -Dcom.sun.xml.ws.transport.http.client.HttpTransportPipe.dump=true -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=7077

 

Verification:

You should see something like following on weblogic console.

weblogicdebug

 

 

And then use debug port 7077 (or anything else) as mentioned in this file.

How to create and integrate NEW repository in ATG

Layman and simple language i will use here.

Repository = 1 property file (responsible for connecting to Data source defined in your application server)

Tools used:

  • Oracle ATG10.2
  • Oracle webllogic server
  • Oracle DB

Steps:

  1. Get DB details (Schema Name, SID, Password, IP, PORT)
  2. Connect to you schema, create a table and insert some data. (Table must have a primary key)
  3. Choose JNDI name of your choice.
  4. Go to Weblogic server where your ATG commerce application will run.
  5. Create a Datasource with any name using JNDI and DB details from Step 1 and 3.
  6. Go to your development tool, i use eclipse.
  7. Create repository property file with any name you like, under any sub folder of “config”. e.g. myrepo.properties

Continue reading