Displaying Images in jsp


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: Displaying Images in jsp

  1. #1
    Join Date
    Jul 2005
    Posts
    54

    Displaying Images in jsp

    Hi,
    In my project,the users are allowed to uploade images.
    I did the uploading of images and stored in the server in a directory and also i stored the link in the database.
    Now i want to display the images that uploaded in the server to change the image name like that.
    I tried like this by taking the image link from the database
    <img src="<%=rs.getString(2)%>" />
    I write the above line the while(rs.next()) loop in order take the values fromt the database.
    This is working fine for displaying images.
    For each image i ve to give a textbox to change the image name as user likes.
    for that i mentioned the <input> tag within the loop by doing so im unable to get the values added in the each text box.
    Can anyone tell me how to do this?
    And one more can anyone tell me how to read and display the image that stored in the server.
    I stored the uploaded image in this mywebapp/username/foldername/file1.jpg,
    mywebapp/username/foldername/file2.jpg like this.
    Can anyone help me out in this.
    Thanx a lot in advance.

  2. #2
    Join Date
    Oct 2004
    Posts
    311
    could you post the entire while(rs.next()) loop?
    that way I can also see how you're input field is setup.

    Oh, and do you have a <form> around all the input fields?

  3. #3
    Join Date
    Jul 2005
    Posts
    54
    Hi,
    Thanx for ur response.
    I tried in two ways.
    The following is one of the way
    <form name="mainform" method="post" action="savedb.jsp">
    <%
    String name=(String)session.getAttribute("theName");
    try
    {
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    Connection con = DriverManager.getConnection("jdbcdbc:foto");
    Statement st = con.createStatement();
    String sql = "select * from album_bookmark where username='"+name+"'";
    ResultSet rs = st.executeQuery(sql);
    while(rs.next())
    {
    %>
    <table>
    <tr>
    <td>
    <img src="<%=rs.getString(2)%>" width="50" height="50">
    <% }
    }catch(Exception ert){out.println(ert.toString());}%>
    <input type="text" name="Name" />
    </td>

    </tr>
    </table>
    <input type="submit" value="Save Changes"/>
    </form>
    In the above code
    I ended the loop and then i add the text box in that the textbox will appear next to the last image.
    The Second way is
    <%@ page import="java.sql.*,java.io.*,java.util.*,java.util.Date" %>
    <form name="mainform" method="post" action="savedb.jsp">
    <%
    String name=(String)session.getAttribute("theName");
    try
    {
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    Connection con = DriverManager.getConnection("jdbcdbc:foto");
    Statement st = con.createStatement();
    String sql = "select * from album_bookmark where username='"+name+"'";
    ResultSet rs = st.executeQuery(sql);
    while(rs.next())
    {
    %>
    <table>
    <tr>
    <td>
    <img src="<%=rs.getString(2)%>" width="50" height="50">
    <input type="text" name="Name" />
    </td>
    </tr>
    </table>
    <% }
    }catch(Exception ert){out.println(ert.toString());}%>
    <input type="submit" value="Save Changes"/>
    </form>
    In the above code for each image textbox will be displayed but while getting the value only one value is possible to get.
    Hope now u r able to help me.
    Thanx a lot for ur response

  4. #4
    Join Date
    Oct 2004
    Posts
    311
    Ok, the problem is that each input filed for the image name has the same name.
    What you need is a way to link the input field to the actual image in the database.

    Would it be a problem to submit each image name seperately?Or do you need to be able to change several of them, then dubmit all of them at once?

    In the first instance, you could do something like:

    Code:
    while(rs.next()) {
     %>
    <form name="mainform" method="post" action="savedb.jsp">
    <input type="hidden" name="imageId" value="<%=rs.getString(1)%>"/>
    <table>
    <tr>
    <td>
    <img src="<%=rs.getString(2)%>" width="50" height="50">
    <input type="text" name="Name" />
    </td>
    <td>
    <input type="submit" value="Save Changes"/>
    </td>
    </tr>
    </table>
    </form>
    <% }
    }
    This approach makes sure each imagename is submitted seperately, along with the ID for the record you wish to change.

    If you need to change all of them at one go, that takes a little more thinking. But I think this will work fine.

    Mark

Similar Threads

  1. image displaying in jsp
    By shivaprasad in forum Java
    Replies: 3
    Last Post: 06-23-2005, 09:38 PM
  2. Replies: 1
    Last Post: 11-22-2001, 11:43 AM
  3. Replies: 0
    Last Post: 01-02-2001, 08:45 AM
  4. Replies: 1
    Last Post: 10-13-2000, 12:39 PM
  5. Displaying TIFF images on the web
    By Bob Smith in forum ASP.NET
    Replies: 2
    Last Post: 08-11-2000, 02:10 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center