Define variable and reference it later : Variable « JSP « Java Tutorial






<%--
  Copyright (c) 2002 by Phil Hanna
  All rights reserved.
  
  You may study, use, modify, and distribute this
  software for any purpose provided that this
  copyright notice appears in all copies.
  
  This software is provided without warranty
  either expressed or implied.
--%>
<%!
   static final String[] COLORS = {
      "#CA9A26",
      "#3BF428",
      "#F7E339",
      "#FF40FF",
   };
%>
<%
   for (int i = 0; i < COLORS.length; i++) {
      String color = COLORS[i];
%>
<div style="background-color: <%= color%>;
            font-size: 12pt;
            font-weight: bold;">
   This is color <%= color %>
</div>
<% } %>








23.2.Variable
23.2.1.Creating a Variable
23.2.2.Define variable and reference it later
23.2.3.Reference variable
23.2.4.Page counter