Java - JSTL, random number between values

Add the bellow tag to your jsp page:

<jsp:useBean id="random" class="java.util.Random" scope="application"/>

, and the followin tag to generate your random number:


Particular case:
Generate a random number, between 1 and 4, in order to display a different background at each page refresh:

<img src="../img/background_${random.nextInt(3)+1}.jpg">


Popular posts from this blog

Hibernate - HibernateException: createQuery is not valid without active transaction