Home Answers Viewqa JSP-Servlet Show image and text on same jsp page

 
 


Manu Ash
Show image and text on same jsp page
1 Answer(s)      2 years and 4 months ago
Posted in : JSP-Servlet

Hi all,

I have to display image and text on the same jsp page. The text and image are both retrived from mysql database. The image is shown correctly on seperate jsp page but when shown with text it is not possible.

Please help me out.

Thanks in advance.

View Answers

January 13, 2011 at 11:01 AM


Hi Friend,

Try the following code:

1)data.jsp:

<%@ page import="java.sql.*,java.io.*,java.util.*" %> 
<HTML>
 <table border="1">
 <tr><th>Name</th><th>Address</th><th>Image</th></tr>
   <%
  try{      
    Class.forName("com.mysql.jdbc.Driver").newInstance();
    Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","root");
    Statement stmt=con.createStatement();
    String strQuery = "select * from data";
    ResultSet rs = stmt.executeQuery(strQuery);
    while(rs.next()){
       %>
      <tr>
      <td><%=rs.getString("name")%></td><td><%=rs.getString("address")%></td>
      <td align="center">

<img src="image.jsp?imgid=<%=rs.getInt(1)%>" width="50" height="50">
</a></td>
      </tr>
      <%
    }
    rs.close();
    con.close();
    stmt.close();
  }
  catch(Exception e)
  {
    e.getMessage();
  }
  %>
 </table>
</HTML>

2)image.jsp:

<%@ page import="java.sql.*,java.io.*,java.util.*" %> 
<%
  int id =  Integer.parseInt(request.getParameter("imgid"));
  try{      
    Class.forName("com.mysql.jdbc.Driver").newInstance();
    Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","root");      
    Statement st=con.createStatement();
    String strQuery = "select image from data where id="+id;
    ResultSet rs = st.executeQuery(strQuery);

    String imgLen="";
    if(rs.next()){
      imgLen = rs.getString(1);
       }  
    rs = st.executeQuery(strQuery);
    if(rs.next()){
      int len = imgLen.length();
      byte [] rb = new byte[len];
      InputStream readImg = rs.getBinaryStream(1);
      int index=readImg.read(rb, 0, len);  
      st.close();
      response.reset();
      response.getOutputStream().write(rb,0,len); 
      response.getOutputStream().flush();        
    }
  }
  catch (Exception e){
    e.printStackTrace();
  }
%>

Thanks









Related Pages:
Show image and text on same jsp page
Show image and text on same jsp page  Hi all, I have to display image and text on the same jsp page. The text and image are both retrived from mysql database. The image is shown correctly on seperate jsp page but when shown
how to show hyperlink website on the same page
how to show hyperlink website on the same page  dear sir: i need to know how can you show a webiste on the same page. for example i want to show... on the same page weather it is left aligned or right. i read somewhere that you
how to display image and text in single jsp page from the mysql database
how to display image and text in single jsp page from the mysql database  hello please help me to display the image and text in single jsp page from mysql database if have any reference code please send me Thanks in advance
Adding image to database through jsp or HTML page ,while adding only image should show.
Adding image to database through jsp or HTML page ,while adding only image should show.   Adding image to database through jsp or HTML page,while adding only image should show. After that i need view that uploaded image from
Fetched Record from database show into text field of html page
Fetched Record from database show into text field of html page  hi, i... is that if i have a report page with same four above filed and i type any letter..., and also have html page with all above mentioned field i have submit 20 record from
Show Hyperlink in HTML Page
Show Hyperlink in HTML Page   ... code show you a HTML page, that create a link to another page. The code begins... to be displayed</a> is used to show the url of the page to which hyperlink
display results on same jsp page
display results on same jsp page  is there any method to display search results from database on the same jsp page where i give the inputs using struts 1.2
display results on same jsp page
display results on same jsp page  is there any method to display search results from database on the same jsp page where i give the inputs using struts 1.2
display results on same jsp page
display results on same jsp page  is there any method to display search results from database on the same jsp page where i give the inputs using struts 1.2
add same tables in jsp page
add same tables in jsp page  hi I have a table in my jsp page with data, now I want to add same copy of table without its default value in same page whenever I click add more table, how do I do
Show spinner while loading image using JavaScript
Show spinner while loading image using JavaScript  Hello sir I am working on a web page which has .png image in middle of it. Other part of the page... and looks exactly the same as before except for the chart in the middle of the page
Servlets errors in same page.
Servlets errors in same page.  How do I display errors list in the same page where a form field exists using servlets...........i.e. without using JSP? Please explain with a simple username password program
gradient text, text effect, text
Menu > Layer Style > Gradient Overlay and make same setting. Final Image... How to make a gradient text       We can make many different type of text by the help
populating a screen on the same page
populating a screen on the same page  i'm making a time table in jsp... to a new page which will help them to choose the subject and faculty through drop... to select the subject and faculty....so that we dont need to redirect to other page
hide and show result in jsp
="sql" uri="http://java.sun.com/jsp/jstl/sql"%> <%@ page language ="java" import="java.sql.*" %> <%@page contentType="text/html" pageEncoding...="http://java.sun.com/jsp/jstl/sql"%> <%@page import="java.sql.*"%>
Image preview - JSP-Servlet
Image preview  How to show the preview of the image when we select the image through browse button in JSP page before storing it in the application... select the image using the file type button i want to dynamically show
Jsp Image prob - JSP-Servlet
Jsp Image prob   I m working on a project i which i have to upload a image in jsp to database and then on next page i will show that image from database so what should i do as i have done first phase
login for different user in the same page
login for different user in the same page  how can i do the login for different user in the same page throug jsp
Redirect to same jsp page on successful login
Redirect to same jsp page on successful login  Hi, I have an application where on successful login, the redirect should happen to same page... from the database. I am unable to create the session for the same login page
How can I output text typed in textarea by user on the same page?
How can I output text typed in textarea by user on the same page?  I have a basic HTML page where I have created a textarea for users comments. I would like to take the comments and append them to the same page for all to see
staying in same page after deliting arow in jsp page - JSP-Servlet
staying in same page after deliting arow in jsp page  Hello Sir, I want to stay back in current jsp page after deleting row in jsp table. how can..., As per your problem visit this link..... http://www.roseindia.net/jsp
How to Autogenerate of ID from database and show on JSP page?
How to Autogenerate of ID from database and show on JSP page?  ... increasin 1 in the previously stored tsk id) on JSP page when I click..." prefix="html"%><%@ page contentType="text/html;charset=windows-1252"%>
How to Autogenerate of ID from database and show on JSP page?
How to Autogenerate of ID from database and show on JSP page?  ... increasin 1 in the previously stored tsk id) on JSP page when I click..." prefix="html"%><%@ page contentType="text/html;charset=windows-1252"%>
How to Autogenerate of ID from database and show on JSP page?
How to Autogenerate of ID from database and show on JSP page?  ... increasin 1 in the previously stored tsk id) on JSP page when I click..." prefix="html"%><%@ page contentType="text/html;charset=windows-1252"%>
How to Autogenerate of ID from database and show on JSP page?
How to Autogenerate of ID from database and show on JSP page?  ... uri="/WEB-INF/struts-html.tld" prefix="html"%><%@ page contentType="text... tasks id as primay key, I am using JSP and struts for database connectivity,Now I
Get form value in same page - JSP-Servlet
Get form value in same page  Hello friends, Can we get a form field value in the same to be processed in java coding... friend, For solving the problem visit to : http://roseindia.net/jsp/user
Posting comments to same page with textarea
Posting comments to same page with textarea  I have been given some code which allows a user to type a comment and on submit it will return the text to the same page. Many thanks for that. However I wanted it to add other
display checked ckeckbox in same jsp page
display checked ckeckbox in same jsp page  how to display checked ckeckbox in same jsp page?   Hi, Here is the html code to display check... ,selected checked checkboxes in another table in same jsp page. (for example
To get the value of more than one text box in an HTML page to a jsp page - JSP-Interview Questions
To get the value of more than one text box in an HTML page to a jsp page  An html file has a text box as To get the value of this text box in a JSP... the value of text boxes to a jsp page and how to access the same
get data in pop up window droplists and on selecting data in the same show a grid table with related datas
get data in pop up window droplists and on selecting data in the same show... to have a text field and a button on my parent jsp page.When i click the button... on the button I need to get the list of hotels in a table grid format on the same
how to upload an image from a jsp page to a mysql database table using jsp
how to upload an image from a jsp page to a mysql database table using jsp  how to upload an image from a jsp page to a mysql database table using jspstrong text
How to Create JSP Page
; In this section we will show you how you can create JSP page and then test on tomcat server. Creating a new JSP page is very simple and any text editor can be used. In this example I will show you how to create a simple JSP page
loading image
loading image  i use two jsp page and one servlet .And i try... animated loading image on 1st JSP while the request is being processed. If I use... how to show animated loading image on regular form submit
How display a Image on Servlet from file upload - JSP-Servlet
How display a Image on Servlet from file upload  Dear Sir, My requirement is I want to display a Image on Servlet from File Upload... by photo gallery.that message show file format not supported by Photo Gallary. I
How to use 'if' statement in jsp page?
How to use 'if' statement in jsp page?  ... how to use 'if' statement in jsp page. This statement is used to test...; in the directory Tomcat-6.0.16/webapps/user/ and you can run this jsp page with url "http
Uploading an image - JSP-Servlet
Uploading an image  I am doing a jsp project. In this uploading an image is a part. For that i had done a coding for uploading. But, it will not check for file size. File path getting had done by a different jsp page
how to send and retrieve image along with text to and from database
how to send and retrieve image along with text to and from database  .... i want to take the random image along with the text and send it to another user...=" + guestbookName); } } //the guestbook.jsp <%@ page contentType="text/html
Display image on JSP page using XML
Display image on JSP page using XML   ... display a image on JSP page by using XML.  This example will examine how to parse and expose XML information using the JAXP with a JSP page. This tutorial
how to use dropdown list in JSP and display value in same page
in the same page Value selected = C How can we do this in a JSP page...how to use dropdown list in JSP and display value in same page  I... one option the value must get displayed below it in the same page
How to show data from database in textbox in jsp
How to show data from database in textbox in jsp   How to show data from database in textbox in jsp   Here is an example that retrieve the particular record from the database and display it in textbox using JSP. <
JSF outputLink Tag
; This is the outputLink which show the output text...: <%@ page contentType="text/html" %> <%@ taglib uri... the file name with the jsf extension for the jsp page, controller understand
Forward a Jsp Page
Forward a Jsp Page In this example program we will show you how to use the <... is not logged in you can forward the user on the login page. Here is the use of <jsp:forward tag: <jsp:forward page="
display contents on the same page by selecting a radio button
display contents on the same page by selecting a radio button  Bill Amount Rs.<input type="text" name="amm"/> Bill Status: Pending<... on the same page under the radio button
Save profile and image to mysql database, and view the image in another jsp page
Save profile and image to mysql database, and view the image in another jsp page  Pls. need help in saving the profile info with the image in mysql database.. some basic code pls in jsp... thanks in advance
JSP Cookies Example
cookies through jsp page and then show the value of the same cookie in another JSP page. Let's understand the cookies. Cookies are short pieces of data sent... JSP Cookies Example   
using ajax and jsp (struts) to login and remain on same page.
using ajax and jsp (struts) to login and remain on same page.  I am... want to remain on same login page and just want to display loggers name ... I don't know how to use struts to remain on same page. What about config file:- <
Text Clock 2
Java: Example - Text Clock 2 In this page we will show you the demo of the Text clock. We have embedded the applet in the web page for easy... be able to see the running text clock.   This is the same as Example - Text
Having problem with image upload....
that the image is getting uploaded.I also right clicked on the home page...Having problem with image upload....  I am uploading profile pictures in my site.But after uploading when I visit my home page where it is supposed
JavaScript hide image
; In this section, we are going to show and hide image on clicking the button using... 'Show', the function showImage() is called and the image will be visible... the image invisible. Here is the code: <html> <h2>Show
to obtain image path
. this is my index.jsp page <p>&lt;%@page contentType="text/html...="text/html; charset=UTF-8"> <title>JSP Page</title>...to obtain image path   i have made a web application in which you can

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.