364,083 Members | 5932 Browsing Online
Community for Developers & IT Professionals
Bytes IT Community

Slideshow for the images

ttamilvanan81
P: 35
Hai everyone,

I need to provide the slideshow for the images.

I have upload the images into database. Then i will retrive all the images from the database and provide the slideshow for those images. I have try with the following jsp code.

Expand|Select|Wrap|Line Numbers
  1. <%@ page language="java" %>
  2. <%@ page import="java.sql.*"%>
  3. <%@ page import="java.sql.Connection.*"%>
  4. <%@ page import="java.awt.image.*"%>
  5. <%@ page import="java.io.*"%>
  6. <%@ page import="java.io.File"%>
  7. <%@ page import="javax.imageio.ImageIO"%>
  8. <%@ page import="java.awt.image.BufferedImage,java.util.*"%>
  9. <%@ page import="java.awt.*"%>
  10. <%
  11. java.util.Vector images = (java.util.Vector)request.getAttribute("images");
  12. %>
  13. <html>
  14. <head>
  15. <title>JSP Page</title>
  16. <SCRIPT LANGUAGE="JavaScript">
  17. <!-- Begin
  18. var Onerotate_delay = 2000; // delay in milliseconds (5000 = 5 secs)
  19. Onecurrent = 0;
  20. var OneLinks = new Array(3);
  21. OneLinks[0] = "http://www.freewarejava.com";
  22. OneLinks[1] = "http://www.javascriptkit.com";
  23. OneLinks[2] = "http://www.dynamicdrive.com";
  24. function Onenext() {
  25. if (document.Oneslideform.Oneslide[Onecurrent+1]) {
  26. document.images.Oneshow.src = document.Oneslideform.Oneslide[Onecurrent+1].value;
  27. document.Oneslideform.Oneslide.selectedIndex = ++Onecurrent;
  28. }
  29. else Onefirst();
  30. }
  31. function Oneprevious() {
  32. if (Onecurrent-1 >= 0) {
  33. document.images.Oneshow.src = document.Oneslideform.Oneslide[Onecurrent-1].value;
  34. document.Oneslideform.Oneslide.selectedIndex = --Onecurrent;
  35. }
  36. else Onelast();
  37. }
  38. function Onefirst() {
  39. Onecurrent = 0;
  40. document.images.Oneshow.src = document.Oneslideform.Oneslide[0].value;
  41. document.Oneslideform.Oneslide.selectedIndex = 0;
  42. }
  43. function Onelast() {
  44. Onecurrent = document.Oneslideform.Oneslide.length-1;
  45. document.images.Oneshow.src = document.Oneslideform.Oneslide[Onecurrent].value;
  46. document.Oneslideform.Oneslide.selectedIndex = Onecurrent;
  47. }
  48. function Oneap(text) {
  49. document.Oneslideform.Oneslidebutton.value = (text == "Stop Slideshow") ? "Start Slideshow" : "Stop Slideshow";
  50. Onerotate();
  51. }
  52. function Onechange() {
  53. Onecurrent = document.Oneslideform.Oneslide.selectedIndex;
  54. document.images.Oneshow.src = document.Oneslideform.Oneslide[Onecurrent].value;
  55. }
  56. function Onerotate() {
  57. if (document.Oneslideform.Oneslidebutton.value == "Stop Slideshow") {
  58. Onecurrent = (Onecurrent == document.Oneslideform.Oneslide.length-1) ? 0 : Onecurrent+1;
  59. document.images.Oneshow.src = document.Oneslideform.Oneslide[Onecurrent].value;
  60. document.Oneslideform.Oneslide.selectedIndex = Onecurrent;
  61. window.setTimeout("Onerotate()", Onerotate_delay);
  62. }
  63. }
  64. function Onetransport(){
  65. window.location=OneLinks[Onecurrent]
  66. }
  67. //  End -->
  68. </SCRIPT>
  69. </head>
  70. <body>
  71. <%-- <jsp:useBean id="beanInstanceName" scope="session" class="beanPackage.BeanClassName" /> --%>
  72. <%-- <jsp:getProperty name="beanInstanceName"  property="propertyName" /> --%>
  73. <TABLE border="0" cellspacing="0" cellpadding="0" align="center">
  74. <TR>
  75. <TD>
  76.     <form name="Oneslideform" >
  77.     <DIV align="center">
  78.     <TABLE width="150" border="1" cellspacing="0" cellpadding="4" bordercolor="#330099">
  79.     <TR>
  80.     <TD bgcolor="#330099">
  81.         <DIV align="center"><B><FONT color="#FFFFFF">Image Slideshow</FONT></B></DIV>
  82.     </TD>
  83.     </TR>
  84.     <TR>
  85.     <TD bgcolor="#FFFFFF">
  86.         <DIV align="center">
  87.         <img src="" width="500" height="400" name="Oneshow" border="1"/>                
  88.         </DIV>
  89.     </TD>
  90.     </TR>
  91. <%
  92. String img="";
  93. for(int i=0; i<images.size(); i++) {
  94. img=String.valueOf(images.elementAt(0));
  95. javax.servlet.http.HttpServletResponse res=null;;
  96. int returnValue = 0;
  97. Connection conn = null;
  98. Statement stmt = null;
  99. ResultSet rs = null;
  100. InputStream in = null;
  101. OutputStream os = null;
  102. Blob blob = null;
  103. String text;
  104. text=request.getParameter("text");
  105. Class.forName("com.mysql.jdbc.Driver");
  106. conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/sample","root","veradis");
  107. %>
  108.     <TR>
  109.     <TD bgcolor="#330099">
  110.         <DIV align="center">
  111.         <SELECT name="Oneslide" onChange="Onechange();">
  112. <%
  113. int i=1;
  114. //String id="14";
  115. String query = "select image,type from tbl_image ";//where name ='"+images.elementAt(0)+"'"; 
  116. Statement st = conn.createStatement();
  117. rs = st.executeQuery(query);
  118. while(rs.next())
  119. {
  120.     byte[] bytearray = new byte[4096];
  121.     int size=0;
  122.     InputStream sImage;
  123.     sImage = rs.getBinaryStream(1);
  124.     response.reset();
  125.     response.setContentType(rs.getString("type"));
  126.     while((size=sImage.read(bytearray))!= -1 )
  127.     {
  128.         response.getOutputStream().write(bytearray,0,size);
  129.     }
  130.     System.out.println("HAI" + i);
  131.     i++;
  132. }
  133. if(images.size()>0) {
  134. for(int j=0;j<images.size();j++) {
  135. %>
  136.         <OPTION value="<%=response.getOutputStream()%>"><%=response.getOutputStream()%></OPTION>
  137. <%
  138. }   }
  139. %>
  140.         </SELECT>              
  141.         </DIV>
  142.     </TD>
  143.     </TR>
  144.  
  145.     <TR>
  146.     <TD bgcolor="#330099">
  147.         <DIV align="center">
  148.         <INPUT type=button onClick="Oneprevious();" value="<<" title="Previous">
  149.         <INPUT type=button name="Oneslidebutton" onClick="Oneap(this.value);" value="Start Slideshow" title="AutoPlay">
  150.         <INPUT type=button onClick="Onenext();" value=">>" title="Next">
  151.         </DIV>
  152.     </TD>
  153.     </TR>
  154.     </TABLE>
  155.     </DIV>
  156.     </form>
  157.   </TD>
  158.   </TR>
  159. </TABLE>
  160. </body>
  161. </html>
But using the above code only one image could be display. I need the slide show for all the images from the database.

And also i need to Reduce the time for upload the image and Retrive the image from database. When we upload the large size of image, that will take more time. But i need to upload and Retrive those type of images with less timing.

Please help me for this.
Sep 5 '07 #1
Share this Question
Share on Google+
1 Reply


ttamilvanan81
P: 35
Hello everyone,

No one there for solve this problem.

I need it's very urgent. So please anybody can help me for this thread.

Waiting for replies

Thanks for useful replies.
Sep 10 '07 #2

Post your reply

Help answer this question



Didn't find the answer to your Java question?

You can also browse similar questions: Java