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: