Display Base64Encoder string(barcode) as image in jsp/email
Hi,
I am trying to display the barcode image in jsp from the Base64Encoder encoded string.
Earlier i tried to set the output stream of barcode image in the response of the HttpServlet. However, this is not working when i view in the mobile device android/iphone.
Now when i use this Base64Encoder, the string which i am passing to the email template(jsp page), i cant able to view the image when i view in the email(outlook).
But when open this outlook content(.mht) in browser(IE 8), able to see the image. Also when forward this email to the android/iphone mobile device, able to see the image.
The barcode image is not displayed only when i open the email directly in the outlook/browser.
Please help me to resolve this issue.
Hi Gopi,
Thanks for your reply.
when i open the email in outlook, i am getting 'If there are problems with how this message is displayed, click here to view in a web browser'. So when i view in browser(IE) on clikc of this link, the email opened from the temporary internet files(AppData\Local\Microsoft\Windows\Temporary Internet Files\Content.Outlook\54AMMRVF\email (4).mht)
Here i am able to see the image.
Suppose if i forward this email to my gmail and opening in a browser, this time i cant see the image. i am getting only the blank space there.
Similar Messages
-
I want to display BLOB image in JSP Using html tags IMG src=
GoodAfternoon Sir/Madom
I Have got the image from oracle database but want to display BLOB image using <IMG src="" > Html tags in JSP page . If it is possible than please give some ideas or
Send me sample codes for display image.
This code is ok and working no problem here Please send me code How to display using html tag from oracle in JSP page.
<%@ page import="java.sql.*" %>
<%@ page import="java.io.*" %>
<%@ page import="javax.swing.ImageIcon;" %>
<%
out.print("hiiiiiii") ;
// declare a connection by using Connection interface
Connection connection = null;
/* Create string of connection url within specified format with machine
name, port number and database name. Here machine name id localhost
and database name is student. */
String connectionURL = "jdbc:oracle:thin:@localhost:1521:orcl";
/*declare a resultSet that works as a table resulted by execute a specified
sql query. */
ResultSet rs = null;
// Declare statement.
PreparedStatement psmnt = null;
// declare InputStream object to store binary stream of given image.
InputStream sImage;
try {
// Load JDBC driver "com.mysql.jdbc.Driver"
Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
/* Create a connection by using getConnection() method that takes
parameters of string type connection url, user name and password to
connect to database. */
connection = DriverManager.getConnection(connectionURL, "scott", "root");
/* prepareStatement() is used for create statement object that is
used for sending sql statements to the specified database. */
psmnt = connection.prepareStatement("SELECT image FROM img WHERE id = ?");
psmnt.setString(1, "10");
rs = psmnt.executeQuery();
if(rs.next()) {
byte[] bytearray = new byte[1048576];
int size=0;
sImage = rs.getBinaryStream(1);
//response.reset();
response.setContentType("image/jpeg");
while((size=sImage.read(bytearray))!= -1 ){
response.getOutputStream().write(bytearray,0,size);
catch(Exception ex){
out.println("error :"+ex);
finally {
// close all the connections.
rs.close();
psmnt.close();
connection.close();
%>
ThanksI have done exactly that in one of my applications.
I have extracted the image from the database as a byte array, and displayed it using a servlet.
Here is the method in the servlet which does the displaying:
(since I'm writing one byte at a time, it's probably not terribly efficient but it works)
private void sendImage(byte[] bytes, HttpServletRequest request, HttpServletResponse response) throws IOException {
ServletOutputStream sout = response.getOutputStream();
for(int n = 0; n < bytes.length; n++) {
sout.write(bytes[n]);
sout.flush();
sout.close();
}Then in my JSP, I use this:
<img src="/path-to-servlet/image.jpg"/>
The name of the image to display is in the URL as well as the path to the servlet. The servlet will therefore need to extract the image name from the url and call the database. -
Hi All,
I have image in KM folder. I want to display it in JSP as a html image. I am able to
access the image using below code.
<%
try {
IUser sapUser = componentRequest.getUser();
com.sapportals.portal.security.usermanagement.IUser ep5User = WPUMFactory.getUserFactory().getEP5User(sapUser);
IResourceContext resourceContext = new ResourceContext(ep5User);
String path = "/documents/Images/sample.gif";
RID imgRID = RID.getRID(path);
IResource resource = ResourceFactory.getInstance().getResource(imgRID, resourceContext);
BufferedInputStream bufIn = new BufferedInputStream(resource.getContent().getInputStream());
byte[] imagebyte = new byte[bufIn.available()];
bufIn.read(imagebyte);
catch(Exception e ) { }
%>
<img border="0" width="147" height="66" src="">
Using above code image is stored in a byte array. How to set this as html img tag source.
Thanks
JoeHello Sreekanth,
there are two approaches how to get an KM image into your JSP.
<b>1) The easy one</b>
Just put into SRC attribute of your IMG tag next link:
<b>/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/</b>documents/Images/sample.gif
Bold part is an access link to KM root. In this case - be aware, the users have to have access rights to given KM object (could be inherited from parent folder).
<b>2) Through a stream</b>
In this case you don't have to set access rights for a given resource for all users, you will read the image from Runtime (using ice_service context for example).
And you can refer to that image as you refer your application. The only thing you need to do - is to write image byte stream to response in your application. Example:
ByteArrayOutputStream PictureStream = ...;
if (request.getParameter("Get_Image") != null) {
response.setContentType("image/gif");
ServletOutputStream sos = response.getOutputStream();
response.setHeader("Content-Disposition", "attachment; filename="image.gif"");
response.setHeader("Cache-Control", "no-cache");
PictureStream.writeTo(sos);
sos.close();
return;
And then you address this image stream in your SRC attribute of IMG tag following:
<u><i><your application url absolute or relative (relative is siggested)>?Get_Image=true</i></u>
regards,
mz -
ADF BC:Displaying Image On JSP page
Hai All
I'm using ADF BC and JDev 10.1.3.
I want to show an image on my jsp page from database.
For this I have written an servlet with the following code
response.setContentType("image/gif");
OutputStream os = response.getOutputStream();
String amDef = "package.AppModuleName";
String config = "Configuration Name";
ApplicationModule am = Configuration.createRootApplicationModule(amDef, config);
ViewObjectImpl vo =
(ViewObjectImpl)am.findViewObject("ViewObject"); // get view object (the same as used in the table)
System.out.println("vo:" + vo);
vo.executeQuery();
Row row = vo.first();
BlobDomain image = (BlobDomain)row.getAttribute("field");
//System.out.println("image:" + image);
InputStream is = image.getInputStream();
// copy blob to output
byte[] buffer = new byte[10 * 1024];
int nread;
while ((nread = is.read(buffer)) != -1)
os.write(buffer, 0, nread);
os.close();
Configuration.releaseRootApplicationModule(am, false);
This servlet working perfectly.The image is displayed on the page while running
the servlet alone.
My problem is the image is not got displyed on the jsp page
I tried following code to call the servlet
<af:objectImage source="ImageServlet"/>
<img src="ImageServlet" width="140px" height="50px" align="right">
Where ImageServlet is the url-pattern in the web.xml for the servlet
Both method are not working
Any body please help me.......
what I'm missing..............
Is there any other way to display an image on JSP page using backing bean
method.
Thanks
AnsHI,
See: http://kuba.zilp.pl/?id=241
Kuba -
HELP!!!!Display blob image using JSP
Hi,
I am trying to blob image using JSP but it did not display successfully.
Can someone help, please?
below are the codes snippet:
<td>
<img src="display_image.jsp?ID=<%=request.getParameter("ID") %>" width="115" border="0">
</td>
byte[] image_blob = details.getImageByteArray();
response.setContentType("image/jpeg");
//response.setContentType("image/gif");
//BEGINNING OF SECTION TO DISPLAY IMAGE
/*OutputStream fos = null;
fos = response.getOutputStream();
fos.write(image_blob, 0, image_blob.length);
fos.flush();
fos.close();*/
java.io.FileOutputStream fos1 = new java.io.FileOutputStream("C:\\"+id+".jpg");
fos1.write(image_blob);
fos1.close();
OutputStream o = response.getOutputStream();
System.out.println("o");
o.write(image_blob);
System.out.println(image_blob);
System.out.println("write image");Use Java Image or BufferedImage instead of obscure byte array for image data.
Here's an example code for a JSP document:
<%
String wid = request.getParameter("percent");
String cost = request.getParameter("suchi");
response.reset(); //IMPORTANT !
response.setContentType("image/jpeg");
// for testing purpose
if (wid == null) wid = "58";
if (cost == null) cost = "3400";
float dleng = Float.parseFloat(wid) * 2.6f;
RenderedImage rimg = drawGraph(dleng);
OutputStream os = response.getOutputStream();
try{
ImageIO.write(rimg, "jpg", os);
catch(IOException e){
os.flush();
%>
<%!
public RenderedImage drawGraph(float barLength){
final int w = 800;
final int h = 18;
final int x = 0;
final int y = 0;
BufferedImage img = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
Graphics2D g2 = img.createGraphics();
Color c = new Color(Integer.parseInt("FF9999", 16));
g2.setColor(Color.yellow);
g2.fillRect(x, y, w, h);
g2.setColor(c);
g2.fillRect(x, y, (int)barLength, h);
g2.dispose();
return img;
%> -
Problem with displaying BLOB images on JSP page using a servlet
hi. I have a big problem with displaying BLOB images using JSP. I have a servlet that connects to the oracle database, gets a BLOB image , reads it, and then displays it using a BinaryStream. The problem is , this works only when i directly call that servlet, that is http://localhost:8080/ImageServlet. It doesn't work when i try to use that servlet to display my image on my JSP page (my JSP page displays only a broken-image icon ) I tried several coding approaches with my servlet (used both Blob and BLOB objects), and they work just fine as long as i display images explicitly using only the servlet.
Here's what i use : ORACLE 10g XE , Eclipse 3.1.2, Tomcat 5.5.16 , JDK 1.5
here is one of my image servlet's working versions (the essential part of it) :
BLOB blob=null;
rset=st.executeQuery("SELECT * FROM IMAGES WHERE ID=1");
while (rset.next())
blob=((OracleResultSet)rset).getBLOB(2);
response.reset();
response.setContentType("image/jpeg");
response.addHeader("Content-Disposition","filename=42.jpeg");
ServletOutputStream ostr=response.getOutputStream();
InputStream istr=blob.getBinaryStream(1L);
int size=blob.getBufferSize();
int len=-1;
byte[] buff = new byte[size];
while ((len=istr.read( buff ))!=-1 ) {
ostr.write(buff,0,len);
response.flushBuffer();
ostr.close(); and my JSP page code :
<img src="/ImageServlet" border="0" > If you could just tell me what i'm doing wrong here , or if you could show me your own solutions to that problem , i would be very greatful ,cos i'm realy stuck here , and i'm rather pressed for time too. Hope someone can help.I turns out that it wasn't that big of a problem after all. All i had to do was to take the above code and place it into another JSP page instead of into a servlet like i did before. Then i just used that page as a source for my IMG tag in my first JSP. It works perfectly well. Why this doesn't work for servlets i still don't know, but it's not a problem form me anymore . Ofcourse if someone knows the answer , go ahead and write. I would still appriceatte it.
here's the magic tag : <img src="ImageJSP.jsp" border="0" > enjoy : ) -
I create a JSP portlet. But The portlet can't display image(gif file, jpg file). I have modified the provider.xml and the following line is added:
<imageURL>URL_Path</imageURL>
But, the image still cannot be displayed.
How can I display image in JSP portlet?Leo Cheung,
You could try the following :
1. Add a virtual directory path Alias 'imgf' in the Apache configuration file httpd.conf to load the image file. Add the following line under the alias section :
Alias /imgf/ "<your directory>\images/"
2. Place your gif/jpg files (eg., work.gif) in the images directory.
3. Use the IMG tag of HTML :
<IMG src="/imgf/work.gif" border=0 width=80 height=80> in the JSP file at the location where you need to display the image.
Hope this helps
Pushkala -
How to display uploaded image in jsp page.
Hello,
I am using struts 1.2.9 and and have uploaded image on the server. Now what I want to do display the image in jsp page after clicking on one link in jsp. I have tried many thing to display image in jsp page. But I am getting an error during displaying image in jsp. I have displayed absolute path in servlet. and used InputStream and outputstream to display image in jsp page.
Can any one help.
Thanks in advance
Manveer SinghFollow this. This topic is very popular recently on the forum.
-
How to dynamically display images in JSPs
This took a little while to figure out so I thought I'd share. After
doing some research I was led to the following approach on how to load
images from an Oracle database into a JSP:
The "main" JSP:
<HTML>
<head>
<title>Image Test</title>
</head>
<body>
<center>
hello
<P>
<img border=0 src="getImage.jsp?filename=2cents.GIF">
<P>
<img border=0 src="getImage.jsp?filename=dollar.gif">
<P>
world
</body>
</HTML>
And this is the image getter:
<% try {
response.setContentType("image/gif");
String filename = (String) request.getParameter("filename");
java.sql.Connection conn =
java.sql.DriverManager.getConnection("jdbc:weblogic:pool:orapool"); //
connect to db
java.sql.Statement stmt = conn.createStatement();
String sql = "select image from testimage where filename = '" +
filename + "'";
java.sql.ResultSet rs = stmt.executeQuery(sql);
if (rs.next()) {
byte [] image = rs.getBytes(1);
java.io.OutputStream os = response.getOutputStream();
os.write(image);
os.flush();
os.close();
conn.close();
catch (Exception x) { System.out.println(x); }
%>
The thing to note is that there are no <%@ page import="..." %> or <%@
page contentType="..." %> tags - just the single scriptlet. It
seems that for every "<%@" the weblogic compiler sees it puts
out.print("\r\n"); statements in the generated java source.(???) I
don't know much about how browsers work but I think that once it sees
flat ascii come at it it treats everything that follows as text/plain
which is incorrect for the binary stream that's being sent. Another
work around was to set out = null; but that's kind of ugly and might
produce server errors. The real fix is to write a bean to handle images
which I'll work on next (does anybody have any hints on how to do
that?)
-Erik.
PS, thank you to the people that posted info in this group that helped
me track down this problem. -
Erik,
No need to write a bean, just write a serverlet...
you can use this function (however you might want to include some
improved error handeling)
Oh, FYI to prevent caching by the browser you might want to pass a parameter
into the creation of the image like timeseconds or (in my case) variable
text which
was included into the image produced. (You need not even use the variable in
the code, the server is not bright enough to tell)
<IMG SRC=".....MyImageProducer?file=my.jpeg×ecs=12345134">
Jay L. Toops
public boolean httpJpegStreamWriter(BufferedImage ib, HttpServletResponse
response) {
try {
javax.servlet.ServletOutputStream myout = response.getOutputStream();
byte b[] = new byte[1024];
response.setContentType("image/jpeg");
//File file = new File("./myserver/public_html", "testjlt.jpg");
//FileOutputStream fos = new FileOutputStream(file);
ByteArrayOutputStream fos = new ByteArrayOutputStream();
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(fos);
JPEGEncodeParam param = encoder.getDefaultJPEGEncodeParam(ib);
param.setQuality(1.0f,false);
encoder.setJPEGEncodeParam(param);
encoder.encode(ib);
b = fos.toByteArray();
response.setContentLength(b.length);
myout.write(b, 0, b.length);
myout.flush();
myout.close();
} catch (Exception e) {
System.out.println("MY httpJpegStreamWriter Exception\n is :"+
e.toString());
return(false);
return(true);
Erik Lindquist wrote:
> This took a little while to figure out so I thought I'd share. After
> doing some research I was led to the following approach on how to load
> images from an Oracle database into a JSP:
>
> The "main" JSP:
>
> <HTML>
> <head>
> <title>Image Test</title>
> </head>
> <body>
> <center>
> hello
> <P>
> <img border=0 src="getImage.jsp?filename=2cents.GIF">
> <P>
> <img border=0 src="getImage.jsp?filename=dollar.gif">
> <P>
> world
> </body>
> </HTML>
>
> And this is the image getter:
>
> <% try {
> response.setContentType("image/gif");
> String filename = (String) request.getParameter("filename");
> java.sql.Connection conn =
> java.sql.DriverManager.getConnection("jdbc:weblogic:pool:orapool"); //
> connect to db
> java.sql.Statement stmt = conn.createStatement();
> String sql = "select image from testimage where filename = '" +
> filename + "'";
> java.sql.ResultSet rs = stmt.executeQuery(sql);
> if (rs.next()) {
> byte [] image = rs.getBytes(1);
> java.io.OutputStream os = response.getOutputStream();
> os.write(image);
> os.flush();
> os.close();
> }
> conn.close();
> }
> catch (Exception x) { System.out.println(x); }
> %>
>
> The thing to note is that there are no <%@ page import="..." %> or <%@
> page contentType="..." %> tags - just the single scriptlet. It
> seems that for every "<%@" the weblogic compiler sees it puts
> out.print("\r\n"); statements in the generated java source.(???) I
> don't know much about how browsers work but I think that once it sees
> flat ascii come at it it treats everything that follows as text/plain
> which is incorrect for the binary stream that's being sent. Another
> work around was to set out = null; but that's kind of ugly and might
> produce server errors. The real fix is to write a bean to handle images
> which I'll work on next (does anybody have any hints on how to do
> that?)
>
> -Erik.
>
> PS, thank you to the people that posted info in this group that helped
> me track down this problem. -
-
I have to display image on jsp page with some text output. This image is already saved at a location parallel to web-inf and is generated dynamically using a servlet. I have used img tag html to display the image. Other outputs are taking their values from database.
First problem is that image will be taking time to display in comparision of other outouts from database. I have to refresh the page to get imageon my page.
Second is that if I save image in a folder parallel to web-inf in my project then it will not be displaying the image.
Can I use any jsp functionality to display image with other outputs from database. I have used "*include*". but it shows only that image and other outputs.Best way is to use a servlet for this.
<img src="path/to/imageservlet?id=someidentifier">
<!-- or -->
<img src="path/to/imageservlet/someidentifier">In the servlet's doGet() just write code which gets an InputStream of the image (either directly generated, or just read from the local disk file system, if necessary with help of ServletContext#getRealPath(), or even from the DB by ResultSet#getBinaryStream()) and writes it to the OutputStream of the response. That's basically all. Don't forget to buffer the streams properly to speedup performance and to save memory.
You can find here a basic example: [http://balusc.blogspot.com/2007/04/imageservlet.html]. -
Problem in displaying image on jsp page
I want to display an image on jsp page.I copied the image the image in WebContent folder.
I am able to see the image on the design pane when using the following code:-
<img src="/image.gif" height="50" width="50"> but when i run it in the browser nothing gets diplsyed.
also when i use the image container and select the source option that image is not displayed in the WebContents file..plz help.Hi,
Seems that the Problem is there with the way how you specifuied the Image relative Path:
You have specified the below: The opath of image starts with (/) forward slash:
*<img src="/image.gif" height="50" width="50">*
It means to access this Image WebLogic Container will form a Path like this:
http://localhost:7001/image.gif
BUT may be the image is available inside your Context root: So Change the <Img> tag like following in your JSP:
*<img src="image.gif" height="50" width="50">*
(*NOTE:* Never Start your src path with a Preceesing /)
Now WLE will consider the path like below ..if your Applications Context root is "TestApp"
http://localhost:7001/TestApp/image.gif
I am Assuming that Inside the TestApp Application "image.gif" And "your.jsp" jSP pages are Co-Located (Means available in the Same Directory).
Thanks
Jay SenSharma
http://jaysensharma.wordpress.com (WebLogic Magical Stuff) -
Hi guys,
How do I Display a string from a servlet into a JSP Page...
Ive tried so many bloody things!.....
Simply.
I get text from JSP. The servlet does what ever it does to the string.
Now. Ive create sessions and bean things,.... how the hell do I display it in a text box... I can display on the screen.. but not in the text box.!!!
please help!!!hmmm, I dont really like using JSP programming, u should be using JAVA..
the way to do it is:
Call and cast to the bean like this:
<%@ page import="beans.*" %>
<% //cast to bean get request create object
userNameBean u= (userNameBean) request.getSession().getAttribute("userNameBean");
then... all you do is call it like this:
<input type="text" name="firstName" value="<%= u != null? u.getFirstName(): "" %>">
this is the real programmers way,,,
chet.~ -
Displaying Image In JSP for Mozilla Browser
Hai all
How to display the .gif image in JSP file using Mozilla browserdo you really think you give enougth information???
the answer to your question is using the html tag <img src='image_url'> -
How to display stored image in jsp in ie7???
i am using internet explore7. i have a problem when i am displaying an image in jsp its not properly coming. this image and image is stored in database.
image is stored in database using "binarystream" .
i am just simply calling the image path and using the html image display tag.
<img src="<%=fileIpath%>" but image is not coming properly but this image is showing properly in lower ie version.
Can anyone help me???can anyone reply this question??Appearently no.
It might be that the question is not interesting enough to attract people.
Or it might be that the details you provided do no suffice and some important pieces of information are missing. For eample: what are the contents of the variable? If you save the generated page, what do you get? -
Any other way to display the images in jsp
Dear All,
I had a program in get the image in database and display the image in jsp file.
Generally we are using
setContenttype(image) and write the binary values in jsp file,
is there any other way to store the jpeg file in speciefied folder and view the jsp fileIs there any other way to play the shuffle in a car if it doesn't have an aux facility???
There is not.
Or I wondered if you could play it through a smart tv...or do you need an apple tv box???
Not with the Apple TV, but if the Smart TV has an AUX port, you can connect it that way.
B-rock
Maybe you are looking for
-
How can I convert the files in my ipod to the original mp3 and jpegs?
My computer recently crashed and my ipod has most of my photos, music and contacts. I am using windows OS and my question is how come you guys dont have software that will covert IPOD's files to windows viewable/playable formats? This is very unfair
-
White Macbook (purchased in march of this year) keyboard no longer works.
I was typing something, and as soon as I plugged my ipod in, the computer started going crazy. if i clicked in a typeable space (Adress bar of the internet, word processors, anything) it repeated the "b" key endlessly. not knowing what to do, i shut
-
Firefox has slow start up & I have the latest version. IE, Chrome, AOL start right away. Firefox takes up to 10 minutes. == This happened == Every time Firefox opened == when updated to 3.6
-
Photoshop CC not in Application folder or anywhere
I bought the Lightroom/Photoshop combo and Lightroom was installed and Photoshop shows its installed and uptodate but it does not exist any where.
-
How to get regain "other" memory
I have almost 3 gigs of memory taken by "other." By now, it seems that Apple should have a remedy other than restoring the entire phone. Has there been any update to this problem? Restoring my phone is too cumbersome.