How can I randomly display blocks of text in a .jsp file?
February 25, 2007 1:44 PM
Subscribe
How do I output random blocks of text in a JSP include? I am not in any way a java/jsp programmer.
I have an application that uses JSP includes to display advertising (Google AdSense) to visitors. Currently, the ads are fairly static in size and content...I'd like to mix it up a little, have different sizes displayed, and occasionally have no ads at all.
Is there a way to do this just inside the .jsp file? Ideally I'd like to be able to specify what percentage of displays each will get (roughly...doesn't need to be perfect), like one ad block showing up 10% of the time and another 90%. That's not a requirement for this though.
Thanks!
posted by Kickstart70 to computers & internet (8 comments total)
<%
double d = Math.random();
if(d < 0.2){%>text block one<%}
else if(d < 0.4){%>text block 2%<%}
else {%>text block three<%}%>
posted by delmoi at 2:02 PM on February 25, 2007