Images don't load, Help please..

Discussion in 'JSP' started by isis13, Jan 1, 2010.

  1. isis13

    isis13 New Member

    Joined:
    Jan 1, 2010
    Messages:
    7
    Likes Received:
    0
    Trophy Points:
    0
    Hello

    Being new here, I apologize if this is in the wrong subsection (I did see the java section, but am not sure my error lies there).

    I have been assigned a project where I am to create a server that lets clients connect and run a simulation, which runs on the server and gives the output to the client. The server requires matlab and gnuplot. The ouputs consist of 6 graphs created from the output data of matlab using gnuplot.

    I am using netbeans6.1's run and deploy to test (hence am using Apache Tomcat 6.0.18 )

    I am using a random string generator to use as a clients session and storing it in a cookie. The graphs are created on the server using this random string as part of its name (eg. <name>Ia.png).

    Thus, to load this image, I am using a javascript to fetch the cookie with the name and then I display the image using document.write("<img src=\""+FILENAME+"\"></img>");

    The problem that i encounter when i run this is that the client side shows a broken link (I have checked the link path, it is correct). Now the interesting thing is this; while the client is showing this broken link, if I force an event in netbeans (like say simply ctrl+s or even switch to a different tab to see another file/output), and then ask the client to refresh, the image loads just fine?! Through this, it is confirmed that the link path is correct.

    I have no idea why this is occurring or any way to solve this and my deadline approaches so I would highly appreciate it if anybody could give even the slightest insight to what/why is this happening.

    Thanks
     
  2. nimesh

    nimesh New Member

    Joined:
    Apr 13, 2009
    Messages:
    769
    Likes Received:
    20
    Trophy Points:
    0
    Occupation:
    Oracle Apps Admin
    Location:
    Mumbai
    Home Page:
    http://techiethakkar.blogspot.com
    In the below code, why are you using "\" after the filename?
    document.write("<img src=\""+FILENAME+"\"></img>");

    Check the output from the clients side, I mean check the HTML using view-> source from the browser after the page gets loaded. Check if the html appears correctly.
     
  3. isis13

    isis13 New Member

    Joined:
    Jan 1, 2010
    Messages:
    7
    Likes Received:
    0
    Trophy Points:
    0
    This is the code that i now have for printing the image:

    Code:
    var n=get_cookie("fname");
    document.write('<img src="'+n+'Ia.png\"></img>');
    
    Here, the filename is the concatenation of the value of fname cookie and "Ia.png", the \ is an escape sequence for the " coming at the end of the image file name.


    Here is the entire code:
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
        <head>
            
            <title></title>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
            <script type="text/javascript"> 
    
                //Function to get cookis on the server side from the client's browser .
                function get_cookie ( cookie_name )
                {
                    var results = document.cookie.match ( '(^|;) ?' + cookie_name + '=([^;]*)(;|$)' );
    
                    if ( results )
                        return ( unescape ( results[2] ) );
                    else
                        return null;
                }
                
                
                    
                    
               
        </script>
        </head>
        <body bgcolor=#1953a0>
    
            
            
            
             
            
               
            
            <center>
                <script type="text/javascript">
                    
                    var n=get_cookie("fname");
                 
                    document.write('<img src="'+n+'Ia.png\"></img>');
                     
                    
                </script>
                
            </center>
            
        </body>
    </html>
    
    Any thoughts?
     
  4. nimesh

    nimesh New Member

    Joined:
    Apr 13, 2009
    Messages:
    769
    Likes Received:
    20
    Trophy Points:
    0
    Occupation:
    Oracle Apps Admin
    Location:
    Mumbai
    Home Page:
    http://techiethakkar.blogspot.com
    did not noticed that it's an excape sequence :)

    did you check the output on client side?
    view source from the browser...
     
  5. isis13

    isis13 New Member

    Joined:
    Jan 1, 2010
    Messages:
    7
    Likes Received:
    0
    Trophy Points:
    0
    Thanks for the quick reply.

    The code i've shown above (2nd code), is the html i get after i view source on client's browser..
     
  6. nimesh

    nimesh New Member

    Joined:
    Apr 13, 2009
    Messages:
    769
    Likes Received:
    20
    Trophy Points:
    0
    Occupation:
    Oracle Apps Admin
    Location:
    Mumbai
    Home Page:
    http://techiethakkar.blogspot.com
    ok.

    try making the below 2 lines the part of script tags within the header.

    var n=get_cookie("fname");
    document.write('<img src="'+n+'Ia.png\"></img>');

    Or better make a function, and call that function from <body onLoad=function_name()>
     
  7. venami

    venami New Member

    Joined:
    Dec 26, 2008
    Messages:
    195
    Likes Received:
    10
    Trophy Points:
    0
    Occupation:
    Software Professional
    Location:
    India, Tamil Nadu, Cuddalore
    Home Page:
    http://mvenkatapathy.wordpress.com
    Code:
    document.write('<img src="'+n+'Ia.png\"></img>');
    
    Try changing the above line as below:

    Make sure there is a "slash" (/ in case of Linux or \ in case of Windows) in the variable 'n'.
    If there is no slash in the 'n' variable, do as follows:

    Code:
    document.write('<img src="' + n + '[COLOR="Blue"]/[/COLOR]Ia.png"></img>'); [COLOR="Blue"]//here escape both the " quote or else don't escape both of them.[/COLOR]
    
    I think you are not getting the image due to the absence of the slash.
     
    Last edited: Jan 4, 2010
  8. isis13

    isis13 New Member

    Joined:
    Jan 1, 2010
    Messages:
    7
    Likes Received:
    0
    Trophy Points:
    0
    I tried making it a function in the header and use <body onLoad=function_name()>
    and also tried the slash venami mentioned, but neither seemed to solve the problem..

    The funny part is, that though this gives a broken link (and 404 if i right click and select 'view image'), if i make anything event in netbeans (the ide hosting this code) like change some tab or something like that and then refresh the page, the image appears. This leads me to believe that the path at least is correct since nothing happens to the path. I have also verified that the images do get created in my content folder.
     
  9. isis13

    isis13 New Member

    Joined:
    Jan 1, 2010
    Messages:
    7
    Likes Received:
    0
    Trophy Points:
    0
    Edit:
    I tried running tomcat completely independently of netbeans and the problem still persists, and this time, i cannot click anywhere (like changing a tab in the netbeans ide) so that the image loads.
     
  10. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    The problem is not with your server but looks like you have url where there is no image file
     
  11. isis13

    isis13 New Member

    Joined:
    Jan 1, 2010
    Messages:
    7
    Likes Received:
    0
    Trophy Points:
    0
    I kind of doubt that since:

    maybe if i am able to refresh the server at a certain time interval automatically (no idea how to though)... just a random thought..
     
  12. isis13

    isis13 New Member

    Joined:
    Jan 1, 2010
    Messages:
    7
    Likes Received:
    0
    Trophy Points:
    0
    pleas help, this project is due for deployment in a week and this is the only bug left..
     
  13. nimesh

    nimesh New Member

    Joined:
    Apr 13, 2009
    Messages:
    769
    Likes Received:
    20
    Trophy Points:
    0
    Occupation:
    Oracle Apps Admin
    Location:
    Mumbai
    Home Page:
    http://techiethakkar.blogspot.com
    Don't know what's the problem :(
     
  14. ManzZup

    ManzZup New Member

    Joined:
    May 9, 2009
    Messages:
    278
    Likes Received:
    43
    Trophy Points:
    0
    Occupation:
    Production Manager:Software @ ZONTEK
    Location:
    Sri Lanka
    Home Page:
    http://zontek.zzl.org
    Code:
    
    function rtnVal(){
       return n + "Ia.png";
    }
    
    document.write('<img src="rtnVal()"></img>' />);
    
    or use php much lesser code

    <?php
    $file = n + "Ia.png";
    ?>

    <img src="<?php echo $file ?>" />
     
  15. ManzZup

    ManzZup New Member

    Joined:
    May 9, 2009
    Messages:
    278
    Likes Received:
    43
    Trophy Points:
    0
    Occupation:
    Production Manager:Software @ ZONTEK
    Location:
    Sri Lanka
    Home Page:
    http://zontek.zzl.org
    HEY another thng

    <img> tag DOESNT ends with another </img>
    its juz <img src="" />
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice