Link to home
Start Free TrialLog in
Avatar of huzefaq
huzefaq

asked on

how to check if an image exist in another application

I am trying to check if an image exists inanother application, if yes then show it otherwise don't show it.
I tried the below code but it is not working. It jst shows no image for all.

Any help will be greatly appreciated

<%
      file = new File("http://www.ccim.com/services/member/profile/pictures/"+next_record.getMember_ID()+".jpg");
      out.print(file);
      if(file.exists()){
%>
           <td nowrap width = '33%' align = 'right'>
                   <img src ="http://www.ccim.com/services/member/profile/pictures/<%=next_record.getMember_ID()%>.jpg" width="52" height="75">
           </td>
<%
       }else{
%>
                                                             
             <td nowrap width = '33%' align = 'right'>
           </td>
                                                            
<%
       }
%>
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
when I print the file it prints this out.print(file)
http:\www.ccim.com\services\member\profile\pictures\08914062.jpg (this is an image)
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
http:\www.ccim.com\services\member\profile\pictures\00008477.jpg 
http:\www.ccim.com\services\member\profile\pictures\04688171.jpg 
http:\www.ccim.com\services\member\profile\pictures\06264205.jpg 
http:\www.ccim.com\services\member\profile\pictures\08901225.jpg 
http:\www.ccim.com\services\member\profile\pictures\08914062.jpg
ASKER CERTIFIED SOLUTION
Avatar of enachemc
enachemc
Flag of Afghanistan image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of huzefaq
huzefaq

ASKER

Thanks guys but I am getting an error when i try this code

this is what I tried
----------------------------------------------------------------------------------------------------
<%@ page import="java.net.URL" %>
.
.
.

<%
URL img = new URL("http://www.ccim.com/services/member/profile/pictures/"+next_record.getMember_ID()+".jpg");
      try{
            HttpURLConnection con = img.getConnection();
            if(con.getResponseCode!=HttpURLConnection.HTTP_NOT_FOUND){ %>
                  <td nowrap width = '33%' align = 'right'>
                        <img src ="http://www.ccim.com/services/member/profile/pictures/<%=next_record.getMember_ID()%>.jpg" width="52" height="75">
                  </td>
            <%}else{ %>
                  <td nowrap width = '33%' align = 'right'></td>
            <% }
        }
      catch(IOException e)
      { %>
              <td nowrap width = '33%' align = 'right'></td>  
       <% }%>

------------------------------------------------------------------------------------------------------------------------------------------------------------------
I get this error
-------------------------------------------------------------------------------------------------------------------------------------------------------------------
Unable to compile class for JSP

An error occurred at line: 127 in the jsp file: /templates_public/member_search_results.jsp
Generated servlet error:
HttpURLConnection cannot be resolved to a type

An error occurred at line: 127 in the jsp file: /templates_public/member_search_results.jsp
Generated servlet error:
The method getConnection() is undefined for the type URL

An error occurred at line: 127 in the jsp file: /templates_public/member_search_results.jsp
Generated servlet error:
HttpURLConnection.HTTP_NOT_FOUND cannot be resolved to a type

An error occurred at line: 139 in the jsp file: /templates_public/member_search_results.jsp
Generated servlet error:
IOException cannot be resolved to a type

it's java.net.HttpURLConnection.
Avatar of huzefaq

ASKER

I changed the import to

<%@ page import="java.net.*" %>

but I still get these error

--------------------------------------------------
org.apache.jasper.JasperException: Unable to compile class for JSP

An error occurred at line: 127 in the jsp file: /templates_public/member_search_results.jsp
Generated servlet error:
The method getConnection() is undefined for the type URL

An error occurred at line: 127 in the jsp file: /templates_public/member_search_results.jsp
Generated servlet error:
con.getResponseCode cannot be resolved or is not a field

An error occurred at line: 139 in the jsp file: /templates_public/member_search_results.jsp
Generated servlet error:
IOException cannot be resolved to a type

HttpURLConnection con = new HttpURLConnection(img);
Avatar of huzefaq

ASKER

Thanks, I changed the line but it still gives error

---------------------------------------------------------------------------------------------------------
org.apache.jasper.JasperException: Unable to compile class for JSP

An error occurred at line: 127 in the jsp file: /templates_public/member_search_results.jsp
Generated servlet error:
Cannot instantiate the type HttpURLConnection

An error occurred at line: 127 in the jsp file: /templates_public/member_search_results.jsp
Generated servlet error:
con.getResponseCode cannot be resolved or is not a field

An error occurred at line: 139 in the jsp file: /templates_public/member_search_results.jsp
Generated servlet error:
IOException cannot be resolved to a type

-----------------------------------------------------------------------------------------------------------
sorry about that. Use :

HttpURLConnection con = (HttpURLConnection )img.openConnection();
Avatar of huzefaq

ASKER

no pro.

but it still gives this error. It looks like I need to import a java class for IOException. Would you know which one to import. thanks

-------------------------------------------------------------
org.apache.jasper.JasperException: Unable to compile class for JSP

An error occurred at line: 139 in the jsp file: /templates_public/member_search_results.jsp
Generated servlet error:
IOException cannot be resolved to a type



java.io.IOException
Avatar of huzefaq

ASKER

it works.  Thanks