Home Jsp Simple-jsp-example Setting Colors in JSP

Related Tutorials


 
 

Share on Google+Share on Google+

Setting Colors in JSP

Advertisement
In Jsp also we can set the background color which we want, the font color can be changed. The table can be coloured .

Setting Colors in JSP

        

In Jsp also we can set the background color which we want, the font color can be changed. The table can be coloured . By using the colors code we can give colors according to our wish. 

To make a program over this we are firstly declaring a array of String type and pass the names of various colors as an array in the variable named colors. This array we are declaring inside the declaration tag. To access the array, use scriptlet tag which is used for processing the business logic. Use for loop for the accessing the array of colors. Now to print the array use the expression tag which is used for presentation logic. This way the output will be displayed to you. 

 

Here is the code of the program:

<%!
  String[] colors = {"Green", "yellow", "Black", "Red", "pink"};
%>
<HTML>
  <HEAD><TITLE>Setting Colors Code</TITLE></HEAD>
  <BODY>
    <H1>List of colors</H1>
    <TABLE BORDER="1" align="center" bgcolor="#E8FDFF"
     weight="50%" height="40%">
      <TH>Color Name:</TH>
      <% for (int i=0; i<colors.length; i++) { %>
        <TR><TD bgcolor="<%=colors[i] %>">
     <font color="white"><%= colors[i]%></font></TD></TR>
      <% } %>
    </TABLE>
  </BODY>
</HTML>

Output of the code:

Download this example.

Advertisements

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: February 8, 2008

Related Tutorials

Discuss: Setting Colors in JSP  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:1
ankit sharma
August 27, 2014
This is not Text Color

This is not text color you are changing. This is background color you changed.
DMCA.com