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.getMem ber_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()%>.jp g" 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
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.getMem
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
</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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
it's java.net.HttpURLConnection .
ASKER
I changed the import to
<%@ page import="java.net.*" %>
but I still get these error
-------------------------- ---------- ---------- ----
org.apache.jasper.JasperEx ception: Unable to compile class for JSP
An error occurred at line: 127 in the jsp file: /templates_public/member_s earch_resu lts.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_s earch_resu lts.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_s earch_resu lts.jsp
Generated servlet error:
IOException cannot be resolved to a type
<%@ page import="java.net.*" %>
but I still get these error
--------------------------
org.apache.jasper.JasperEx
An error occurred at line: 127 in the jsp file: /templates_public/member_s
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_s
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_s
Generated servlet error:
IOException cannot be resolved to a type
HttpURLConnection con = new HttpURLConnection(img);
ASKER
Thanks, I changed the line but it still gives error
-------------------------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------
org.apache.jasper.JasperEx ception: Unable to compile class for JSP
An error occurred at line: 127 in the jsp file: /templates_public/member_s earch_resu lts.jsp
Generated servlet error:
Cannot instantiate the type HttpURLConnection
An error occurred at line: 127 in the jsp file: /templates_public/member_s earch_resu lts.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_s earch_resu lts.jsp
Generated servlet error:
IOException cannot be resolved to a type
-------------------------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- -
--------------------------
org.apache.jasper.JasperEx
An error occurred at line: 127 in the jsp file: /templates_public/member_s
Generated servlet error:
Cannot instantiate the type HttpURLConnection
An error occurred at line: 127 in the jsp file: /templates_public/member_s
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_s
Generated servlet error:
IOException cannot be resolved to a type
--------------------------
sorry about that. Use :
HttpURLConnection con = (HttpURLConnection )img.openConnection();
HttpURLConnection con = (HttpURLConnection )img.openConnection();
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.JasperEx ception: Unable to compile class for JSP
An error occurred at line: 139 in the jsp file: /templates_public/member_s earch_resu lts.jsp
Generated servlet error:
IOException cannot be resolved to a type
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.JasperEx
An error occurred at line: 139 in the jsp file: /templates_public/member_s
Generated servlet error:
IOException cannot be resolved to a type
java.io.IOException
ASKER
it works. Thanks
ASKER
this is what I tried
--------------------------
<%@ page import="java.net.URL" %>
.
.
.
<%
URL img = new URL("http://www.ccim.com/services/member/profile/pictures/"+next_record.getMemb
try{
HttpURLConnection con = img.getConnection();
if(con.getResponseCode!=Ht
<td nowrap width = '33%' align = 'right'>
<img src ="http://www.ccim.com/services/member/profile/pictures/<%=next_record.getMember
</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_s
Generated servlet error:
HttpURLConnection cannot be resolved to a type
An error occurred at line: 127 in the jsp file: /templates_public/member_s
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_s
Generated servlet error:
HttpURLConnection.HTTP_NOT
An error occurred at line: 139 in the jsp file: /templates_public/member_s
Generated servlet error:
IOException cannot be resolved to a type