kapilshanaz 0 Newbie Poster

Hi Guys,
I am doing a web based jsp project. Here we primarily read an image and store it to a relative folder.This image is then called in a jsp page. The previous image is loaded instead of the recent one.
I need help from you guys regarding this,
So Kindly reply me for the same..

I'm also attaching the code for it..

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>

        <title>G-Captcha</title>
        <link rel="stylesheet" href="style.css" type="text/css" charset="utf-8" />	

    </head>
    <%

                String img3;
                if (session.getAttribute("url1") != null) {
                    img3 = session.getAttribute("url1").toString();
                } else {
                    img3 = "";
                }


    %> -->
    <body>

        <div id="wrapper">
            <h1><span class="hone"><em>G-</em>Captcha</span>
                <span class="htwo">_</span>
                <span class="hthree">CREATE YOUR CAPTCHA WITH US</span></h1>
            <div id="head-1">
                <div id="head-3">
                    <jsp:useBean class="Database.Dbprocess" id ="db" scope ="request"/>

                    <%
                                //String f="",m="",l="";
                                //String un = session.getAttribute("uname").toString();
                                String ar[];
                                ar = db.profile();
                                String s = db.key();
                                String link = "pic/" + db.pas();
                                //String link="pic/Koala.jpg";
                 //System.out.println(s);



                                if (ar == null) {
                                    response.sendRedirect("LoginError.html");
                                } else {
                                }
                    %>
                    <table width="403" height="101" border="1" cellpadding="5">
                        <form id="form1" method="post" action="Validate">
                            <tr>
                                <td width="98" height="34" bgcolor="#8D0207">USERNAME:</td>
                                <td width="204" align="center" bgcolor="#8D0207">
                                    <p>
                                        <label>
                                            <input type="text" name="text_username" id="text_username" />
                                        </label>
                                    </p>
                                </td>
                                <td width="55" bgcolor="#8D0207">&nbsp;</td>
                            </tr>
                            <tr>
                                <td height="41" bgcolor="#8D0207">PASSWORD:</td>
                                <td align="center" bgcolor="#8D0207">
                                    <p>
                                        <label>
                                            <input type="password" name="text_password" id="text_password" />
                                        </label>
                                    </p>
                                </td>
                                <td bgcolor="#8D0207"><input type="submit" name="button" id="button" value="Login" /></td>
                            </tr>
                        </form>
                    </table>
                </div><table width="402" height="209" border="1" cellpadding="5">
                    <form id="form2" method="post" action="">
                        <tr>
                            <td width="226" rowspan="4" bgcolor="#8D0207"><img src="<%=link%>" alt="" name="" width="225" height="185" align="top" style="background-color: #000000"  />

                            </td>
                            <td width="144" align="center"><p>
                                    <label>
                                        <input type="text" name="textfield3" value="" id="textfield3" />
                                    </label>
                                </p></td>
                        </tr>
                        <tr>
                            <td align="center"><p>
                                    <label>
                                        <select name="select" id="select">
                                            <%
                                                        int i = 0;
                                                        String br[] = ar;

                                                        while (i < br.length - 1) {
                                            %>
                                            <option value="<%=br[i]%>"><%=br[i]%></option>

                                            <%     i++;  }
                                            %>

                                        </select>
                                    </label>
                                </p></td>
                        </tr>
                        <tr>
                            <td align="center">
                                <p>
                                    <label>
                                        <input type="submit" name="button2" id="button2" value="Submit" onclick="check()" />
                                    </label>
                                </p></td>
                        </tr>
                        <tr>
                            <td height="90" bgcolor="#8D0207">Just type in the text-box above the letter present in the left. Also select the right pic from the drop down list as in the background.<br/>
                                <%
                                            String img1 = "";
                                            int j = 1;
                                            if (j == 1) {
                                                img1 = "pic/green.jpg";
                                            } else {
                                                img1 = "pic/red2.jpg";
                                            }
                                %> <img src="<%=img1%>"/> 
                            </td>
                        </tr>
                    </form>
                </table>
            </div>
            <div id="nav">

                <ul>
                    <li><a href="http://www.freewebsitetemplates.com">HOME</a></li>
                    <li><a href="http://www.freewebsitetemplates.com">ABOUT US</a></li>
                    <li><a href="http://www.freewebsitetemplates.com">SERVICES</a></li>
                    <li><a href="http://www.freewebsitetemplates.com">OUR OTHER SITES</a></li>
                    <li class="last"><a href="http://www.freewebsitetemplates.com">CONTACT US</a></li>
                </ul>
            </div>
            <div id="body-left">
                <h2><em>G</em>allery</h2>
                <div id="gallery">
                <!--<div class="gal" id="gzero"><img src="<%=img1%>" width="228" height="153" alt="Pic 1" /></div>-->

                    <div class="gal" id="gzero"><img src="pic/2501931507_08899e7630.jpg" width="228" height="153" alt="Pic 1" /></div>
                    <div class="gal" id="gone"><img src="pic/captcha...jpg" width="59" height="40" alt="Pic 2" /></div>
                    <div class="gal" id="gtwo"><img src="pic/Captcha.jpg" width="56" height="43" alt="Pic 3" /></div>
                    <div class="gal" id="gthree"><img src="pic/captcha.gif" width="59" height="40" alt="Pic 4" /></div>

                    <div class="clear"></div>  captcha..
                </div>
            </div>
            <div id="body-right"><br /><br /><br /><br /><br /><br /><br /><br />
                <h2><em>W</em>elcome</h2>
                <p>This site is created to help you to add captcha to your sites without creating it.</p>
                <h2><em>I</em>nstruction</h2>
                <p>You can remove any link to our websites from this template you're free to use the template without linking back to us.</p>
                <p>This is just a place holder so you can see how the site would look like.</p>
                <p>This is a template designed by free website templates for you for free you can replace all the text by your own text.</p>
                <p>Even more websites all about website templates on <a href="http://www.justwebtemplates.com">Just Web Templates</a>.</p>
                <p>If you're looking for beautiful and professionally made templates you can find them at <a href="http://www.templatebeauty.com">Template Beauty</a>.</p>
                <p>If you're having problems editing the template please don't hesitate to ask for help on <a href="http://www.freewebsitetemplates.com/forum/">the forum</a>.</p>
            </div>
            <div class="clear spacer"></div>
            <div id="footer">
                &copy; 2010 KAPILS
            </div>

        </div>
    </body>
</html>

and im also attaching the Java code with pas() function

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.File;
import java.sql.*;
import java.util.Random;
import javax.imageio.ImageIO;

    public String pas() {

        String outputfile = "";
        int START = 4;
        int END = 8;
        int START1 = 1;
        int END1 = 26;
        int START2 = 10000;
        int END2 = 99999;
        int len, seq, asc, seq1;
        String val = "", con, cards;
        Random random = new Random();
        len = showRandomInteger(START, END, random);
        for (int i = 0; i < len; i++) {
            seq = showRandomInteger(START1, END1, random);
            asc = seq + 96;
            char aChar = (char) asc;
            val = val + aChar;
            //System.out.print(aChar);

        }
        try {
            //System.out.println(val);
            seq1 = showRandomInteger(START2, END2, random);
            //System.out.print(seq1);
            //con=val+seq1;
            //System.out.println(con);
            String no = seq1 + "";
            cards = shuffler(val, no);
            //cards=con;
            //cards=shuffle(cards);
            //jLabel1.setText(cards);

            //for grey
            String m = "";
            try {
                rs = db.SelectedDb("SELECT * FROM addphoto ORDER BY RAND() LIMIT 1");
                ResultSet bbb = rs;
                rs.next();

                m = rs.getString("path");
                System.out.println(m);

            } catch (Exception e) {
            }

            GrayMyImage imageGrayer = new GrayMyImage();

            String inputImageFilePath = "C://Documents and Settings/Student/My Documents/NetBeansProjects/j2ee sample/web/pic/" + m;
            //String outputImageFilePath="C:\\shanu\\greyimage.jpg";

            System.out.println("Reading input image...");
            BufferedImage inputImage = imageGrayer.readImage(inputImageFilePath);
            System.out.println("Successfully Read Image: " + inputImageFilePath);

            System.out.println("\nConverting the image to Gray colors.");
            BufferedImage img = imageGrayer.grayOut(inputImage);
            System.out.println("Successful...");


            //System.out.println("\nWriting gray image to filesystems.");
            //imageGrayer.writeImage(grayedOut,outputImageFilePath , "jpg");
            //System.out.println("Successfully Wrote Image To: "+outputImageFilePath);

            //URL url1 = new URL("file:///C:\\shanu\\Sunset.jpg");           // point link to the source image
            // Image image = ImageIO.read(url1);          // read it
//for resize
            int type2 = img.getType() == 0 ? BufferedImage.TYPE_INT_ARGB : img.getType();

            BufferedImage img1 = resizeImage(img, type2);
            //for merge
            Graphics2D g2 = img1.createGraphics();
            g2.setColor(Color.red);
//int font=22;
            Font font = new Font("chiller", Font.BOLD, 26);



            g2.setFont(font);

            g2.drawString(cards, 30, 125);       // the text



            /*  if u want to save the result on disk*/

            File outputfile1 = new File("C://Documents and Settings/Student/My Documents/NetBeansProjects/j2ee sample/web/pic/kol.jpeg");
            {
                System.out.println(outputfile1.getAbsolutePath());
                ImageIO.setUseCache(false);
                ImageIO.write(img1, "jpeg", outputfile1);




            }

            return outputfile1.getName();

//display the result
//jLabel1.setIcon(new ImageIcon(img1));
        } catch (Exception ex) {
            System.out.println("EEEEEEEEEEEEEr");
            return "err";

        }       // TODO add your handling co



    }

Anyway thanks in advance...