This week's book giveaway is in the Performance forum.
We're giving away four copies of The Java Performance Companion and have Charlie Hunt, Monica Beckwith, Poonam Parhar, & Bengt Rutisson on-line!
See this thread for details.
Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to display image giving dynamic path in HTML

 
vini chauhan
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

My Questions is related to displaying image in html where I need to give a path to image which is not static. For example the image is taken from the database and displayed in html.

<img src="staticlink.jpg/> how to solve this problem?
 
ripu sudan
Greenhorn
Posts: 20
Java Linux Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
String vis=Long.toString(Total_Visitors);
for(int m=0;m<vis.length();m++)
{
int img=0;
char ch;
String str="";
ch=vis.charAt(m);
//str=ch.

img=Character.getNumericValue(ch);
%>
<td><img src="images/<%=img%>.png" ></td>
<%
}
%>



your problum's solution is similar to this "here i am parsing long to string and for each characeter(1,2 etc) i am showing image as "1.png", "2.png" etc
 
vini chauhan
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank You! My Problem Solved
 
ripu sudan
Greenhorn
Posts: 20
Java Linux Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator






 
Sean Clark
Rancher
Posts: 377
Android Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey,

Your solution works fine while your jsp file is at the root of your application, but what happens when you put that JSP in a subfolder or in the WEB-INF?

Also java in jsps is a big no no! You should be using tag libraries and EL instead.

Sean
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64972
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Re-emphasizing: there should never be scriptlets or Java code in JSPs. That's a poor practice that has been discredited for over 8 years now.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic