?
Solved

how to show a default image

Posted on 2006-06-30
5
Medium Priority
?
201 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 28

Accepted Solution

by:
rrz earned 2000 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 28

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

In today's business world, data is more important than ever for informing marketing campaigns. Accessing and using data, however, may not come naturally to some creative marketing professionals. Here are four tips for adapting to wield data for insi…
If you're a modern-day technology professional, you may be wondering if certifications are really necessary. They are. Here's why.
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses
Course of the Month13 days, 4 hours left to enroll

777 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