Solved

how to show a default image

Posted on 2006-06-30
5
195 Views
Last Modified: 2010-08-05
I have this code in which I show an image on a JSP page
<tr>
      <td width="386"><a border ='0' href="/chapters/pub"><img src="/chapters/attachments/images/<%=chapter_ID%>LOGO" width="386" height="61"></a></td>
</tr>

Now how can I write code which checks if an image with this name exists, if it doesn't show a default page

Any help will be greatly appreciated
0
Comment
Question by:huzefaq
  • 3
  • 2
5 Comments
 
LVL 27

Accepted Solution

by:
rrz earned 500 total points
ID: 17020365
Here is one way.  
<%
  File file = new File(application.getRealPath("/chapters/attachments/images/" + chapter_ID + "LOGO"));
  if(file.exists()){
%>
<tr>
     <td width="386"><a border ='0' href="/chapters/pub"><img src="/chapters/attachments/images/<%=chapter_ID%>LOGO" width="386" height="61"></a></td>
</tr>
<%
   }else{ response.sendRedirect(request.getContextPath() + "/default.jsp"); return;}
%>
0
 

Author Comment

by:huzefaq
ID: 17054213
Thanks a lot

I actually end up with this code

<%
file = new File(application.getRealPath("attachments/images/" + chapter_ID + "SIMAGE.jpg"));
if(file.exists()){
              %>
                    <tr>
                        <td><img src="attachments/images/<%=chapter_ID%>SIMAGE.jpg" width="140" height="140"></td>
                    </tr>
              <%
                  }else{
              %>
                    <tr>
                        <td><img src="attachments/images/DefaultSIMAGE.jpg" width="140" height="140"></td>
                    </tr>
              <%
                }
              %>
            
0
 

Author Comment

by:huzefaq
ID: 17054221
If you don't mind I just wanted to know what does this code do

else{ response.sendRedirect(request.getContextPath() + "/default.jsp"); return;}
0
 
LVL 27

Expert Comment

by:rrz
ID: 17054445
>if it doesn't show a default page  
I thought you wanted to go to another page. The code would have redirected the browser.
0
 

Author Comment

by:huzefaq
ID: 17054568
ok, thanks
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Note: This is the third blog post in a series on email clearinghouses (https://www.xmatters.com/alert-management/blog-email-has-failed-us?utm_campaign=70138000000ydLoAAI&utm_source=exex&utm_medium=article&utm_content=blog-post).   We’ve been talki…
In 2017, ransomware will become so virulent and widespread that if you aren’t a victim yourself, you will know someone who is.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

929 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now