I need to do the slideshow action for the database images.
If i get all the images from the Database, i need to provide the slideshow for all those images.

Here is the code for i have done earlier.

<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<%@ page language="java" %>
<%@ page import="java.sql.*"%>
<%@ page import="java.sql.Connection.*"%>
<%@ page import="java.awt.image.*"%>
<%@ page import="java.io.*"%>
<%@ page import="java.io.File"%>
<%@ page import="javax.imageio.ImageIO"%>
<%@ page import="java.awt.image.BufferedImage,java.util.*"%>
<%@ page import="java.awt.*"%>
<%
java.util.Vector images = (java.util.Vector)request.getAttribute("images");
%>
<html>
<head>
<title>JSP Page</title>
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
//3-way slideshow- by Suzanne Arnold (http://jandr.com/, suzanne@mail.jandr.com)
//Script featured on JavaScript Kit (http://javascriptkit.com)
//Credit must stay intact
var Onerotate_delay = 2000; // delay in milliseconds (5000 = 5 secs)
Onecurrent = 0;
var OneLinks = new Array(3);
OneLinks[0] = "http://www.freewarejava.com";
OneLinks[1] = "http://www.javascriptkit.com";
OneLinks[2] = "http://www.dynamicdrive.com";
function Onenext() {
if (document.Oneslideform.Oneslide[Onecurrent+1]) {
document.images.Oneshow.src = document.Oneslideform.Oneslide[Onecurrent+1].value;
document.Oneslideform.Oneslide.selectedIndex = ++Onecurrent;
}
else Onefirst();
}
function Oneprevious() {
if (Onecurrent-1 >= 0) {
document.images.Oneshow.src = document.Oneslideform.Oneslide[Onecurrent-1].value;
document.Oneslideform.Oneslide.selectedIndex = --Onecurrent;
}
else Onelast();
}
function Onefirst() {
Onecurrent = 0;
document.images.Oneshow.src = document.Oneslideform.Oneslide[0].value;
document.Oneslideform.Oneslide.selectedIndex = 0;
}
function Onelast() {
Onecurrent = document.Oneslideform.Oneslide.length-1;
document.images.Oneshow.src = document.Oneslideform.Oneslide[Onecurrent].value;
document.Oneslideform.Oneslide.selectedIndex = Onecurrent;
}
function Oneap(text) {
document.Oneslideform.Oneslidebutton.value = (text == "Stop Slideshow") ? "Start Slideshow" : "Stop Slideshow";
Onerotate();
}
function Onechange() {
Onecurrent = document.Oneslideform.Oneslide.selectedIndex;
document.images.Oneshow.src = document.Oneslideform.Oneslide[Onecurrent].value;
}
function Onerotate() {
if (document.Oneslideform.Oneslidebutton.value == "Stop Slideshow") {
Onecurrent = (Onecurrent == document.Oneslideform.Oneslide.length-1) ? 0 : Onecurrent+1;
document.images.Oneshow.src = document.Oneslideform.Oneslide[Onecurrent].value;
document.Oneslideform.Oneslide.selectedIndex = Onecurrent;
window.setTimeout("Onerotate()", Onerotate_delay);
}
}
function Onetransport(){
window.location=OneLinks[Onecurrent]
}
// End -->
</SCRIPT>
</head>
<body>
<TABLE border="0" cellspacing="0" cellpadding="0" align="center">
<TR>
<TD>
<form name="Oneslideform" >
<DIV align="center">
<TABLE width="150" border="1" cellspacing="0" cellpadding="4" bordercolor="#330099">
<TR>
<TD bgcolor="#330099">
<DIV align="center"><B><FONT color="#FFFFFF">Image Slideshow</FONT></B></DIV>
</TD>
</TR>
<TR>
<TD bgcolor="#FFFFFF">
<DIV align="center">
<img src="" width="500" height="400" name="Oneshow" border="1"/>
</DIV>
</TD>
</TR>
<%
String img="";
for(int i=0; i<images.size(); i++) {
img=String.valueOf(images.elementAt(0));
}
javax.servlet.http.HttpServletResponse res=null;;
int returnValue = 0;
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
InputStream in = null;
OutputStream os = null;
Blob blob = null;
String text;
text=request.getParameter("text");
Class.forName("com.mysql.jdbc.Driver");
conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/sample","root","veradis");
int i=1;
String query = "select image,type from tbl_image ";//where name ='"+images.elementAt(0)+"'";
Statement st = conn.createStatement();
rs = st.executeQuery(query);
while(rs.next())
{
byte[] bytearray = new byte[4096];
int size=0;
InputStream sImage;
sImage = rs.getBinaryStream(1);
response.reset();
response.setContentType(rs.getString("type"));
while((size=sImage.read(bytearray))!= -1 )
{
response.getOutputStream().write(bytearray,0,size);
}
%>
<TR>
<TD bgcolor="#330099">
<DIV align="center">
<SELECT name="Oneslide" onChange="Onechange();">
<%
}
%>
<OPTION value="<%=response.getOutputStream()%>"><%=response.getOutputStream()%></OPTION>
</SELECT>
</DIV>
</TD>
</TR>
<TR>
<TD bgcolor="#330099">
<DIV align="center">
<INPUT type=button onClick="Oneprevious();" value="<<" title="Previous">
<INPUT type=button name="Oneslidebutton" onClick="Oneap(this.value);" value="Start Slideshow" title="AutoPlay">
<INPUT type=button onClick="Onenext();" value=">>" title="Next">
</DIV>
</TD>
</TR>
</TABLE>
</DIV>
</form>
</TD>
</TR>
</TABLE>
<center><a href="search.do">Home</a></center>
</body>
</html>


When i was using this code, the first image only it shows. But i am using the another way for storing the image in filesystem(i.e. store the image in image folder under the project root folder), Then we get those images and provide the slideshow with all those images. The code for this functionality, it's working well.

<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<%@ page language="java" %>
<%@ page import="java.sql.*"%>
<%@ page import="java.sql.Connection.*"%>
<%@ page import="java.awt.image.*"%>
<%@ page import="java.io.*"%>
<%@ page import="java.io.File"%>
<%@ page import="javax.imageio.ImageIO"%>
<%@ page import="java.awt.image.BufferedImage,java.util.*"%>
<%@ page import="java.awt.*"%>
<%
//String width=request.getAttribute("width");
//String height=request.getAttribute("height");
java.util.Vector images = (java.util.Vector)request.getAttribute("images");
%>
<html>
<head>
<title>JSP Page</title>
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
//3-way slideshow- by Suzanne Arnold (http://jandr.com/, suzanne@mail.jandr.com)
//Script featured on JavaScript Kit (http://javascriptkit.com)
//Credit must stay intact
var Onerotate_delay = 2000; // delay in milliseconds (5000 = 5 secs)
Onecurrent = 0;
var OneLinks = new Array(3);
OneLinks[0] = "http://www.freewarejava.com";
OneLinks[1] = "http://www.javascriptkit.com";
OneLinks[2] = "http://www.dynamicdrive.com";
function Onenext() {
if (document.Oneslideform.Oneslide[Onecurrent+1]) {
document.images.Oneshow.src = document.Oneslideform.Oneslide[Onecurrent+1].value;
document.Oneslideform.Oneslide.selectedIndex = ++Onecurrent;
}
else Onefirst();
}
function Oneprevious() {
if (Onecurrent-1 >= 0) {
document.images.Oneshow.src = document.Oneslideform.Oneslide[Onecurrent-1].value;
document.Oneslideform.Oneslide.selectedIndex = --Onecurrent;
}
else Onelast();
}
function Onefirst() {
Onecurrent = 0;
document.images.Oneshow.src = document.Oneslideform.Oneslide[0].value;
document.Oneslideform.Oneslide.selectedIndex = 0;
}
function Onelast() {
Onecurrent = document.Oneslideform.Oneslide.length-1;
document.images.Oneshow.src = document.Oneslideform.Oneslide[Onecurrent].value;
document.Oneslideform.Oneslide.selectedIndex = Onecurrent;
}
function Oneap(text) {
document.Oneslideform.Oneslidebutton.value = (text == "Stop Slideshow") ? "Start Slideshow" : "Stop Slideshow";
Onerotate();
}
function Onechange() {
Onecurrent = document.Oneslideform.Oneslide.selectedIndex;
document.images.Oneshow.src = document.Oneslideform.Oneslide[Onecurrent].value;
}
function Onerotate() {
if (document.Oneslideform.Oneslidebutton.value == "Stop Slideshow") {
Onecurrent = (Onecurrent == document.Oneslideform.Oneslide.length-1) ? 0 : Onecurrent+1;
document.images.Oneshow.src = document.Oneslideform.Oneslide[Onecurrent].value;
document.Oneslideform.Oneslide.selectedIndex = Onecurrent;
window.setTimeout("Onerotate()", Onerotate_delay);
}
}
function Onetransport(){
window.location=OneLinks[Onecurrent]
}
// End -->
</SCRIPT>
</head>
<body>
<%-- <jsp:useBean id="beanInstanceName" scope="session" class="beanPackage.BeanClassName" /> --%>
<%-- <jsp:getProperty name="beanInstanceName" property="propertyName" /> --%>
<TABLE border="0" cellspacing="0" cellpadding="0" align="center">
<TR>
<TD>
<form name="Oneslideform" >
<DIV align="center">
<TABLE width="150" border="1" cellspacing="0" cellpadding="4" bordercolor="#330099">
<TR>
<TD bgcolor="#330099">
<DIV align="center"><B><FONT color="#FFFFFF">Image Slideshow</FONT></B></DIV>
</TD>
</TR>
<TR>
<TD bgcolor="#FFFFFF">
<DIV align="center">
<%
String img="";
for(int i=0; i<images.size(); i++) {
img=String.valueOf(images.elementAt(0));
} %>
<img src="photo/<%=img%>" width="500" height="400" name="Oneshow" border="1"/>
</DIV>
</TD>
</TR>
<TR>
<TD bgcolor="#330099">
<DIV align="center">
<SELECT name="Oneslide" onChange="Onechange();">
<%
if(images.size()>0) {
for(int j=0;j<images.size();j++) {
%>
<OPTION value="photo/<%=images.elementAt(j)%>"><%=images.elementAt(j)%></OPTION>
<%
} }
%>
</SELECT>
</DIV>
</TD>
</TR>
<TR>
<TD bgcolor="#330099">
<DIV align="center">
<INPUT type=button onClick="Oneprevious();" value="<<" title="Previous">
<INPUT type=button name="Oneslidebutton" onClick="Oneap(this.value);" value="Start Slideshow" title="AutoPlay">
<INPUT type=button onClick="Onenext();" value=">>" title="Next">
</DIV>
</TD>
</TR>
</TABLE>
</DIV>
</form>
</TD>
</TR>
</TABLE>
<center><a href="search.do">Home</a></center>
</body>
</html>


Using this code i am getting the images from the photo folder under the project root folder. But i need to get the images from the database.

Please help me with this.


Advance Thanks for your reply

Thanks
Tamilvanan

Recommended Answers

All 3 Replies

Your slide show is done in JavaScript

<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
//3-way slideshow- by Suzanne Arnold

and this has nothing to do with Java

THIS POST WILL BE MOVE TO THE JavaScript section

Nobody's there for help me, to solve this thread.
I need it's urgent please Help me anybody.

Waiting for Reply.
Thanks for useful Replies.

You have JavaScript errors which are stopping execution.

The very first word "Begin" is inside an HTML comment, but it is NOT inside a JavaScript comment. This crashes JS right from the start.

Also, newer browsers ignore EVERYTHING inside the <!-- --> comment tags. JavaScript inside these will not even start on some of the newest browsers. It is better to have an external script file.

Please put your code in [ code ] ... [ /code ] tags when you post (remove the spaces I put in to make them visible). Then the code is more legible.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.