-
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.
-
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?
-
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("jdbc dbc: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("jdbc dbc: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
-
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
-
By shivaprasad in forum Java
Replies: 3
Last Post: 06-23-2005, 08:38 PM
-
By Joshua in forum ASP.NET
Replies: 1
Last Post: 11-22-2001, 10:43 AM
-
Replies: 0
Last Post: 01-02-2001, 07:45 AM
-
By Venkatesh in forum Java
Replies: 1
Last Post: 10-13-2000, 11:39 AM
-
By Bob Smith in forum ASP.NET
Replies: 2
Last Post: 08-11-2000, 01: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
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks