Click to See Complete Forum and Search --> : PB changing FONT COLOR with servlet !!!


trevesp
November 23rd, 2003, 10:46 PM
Hello,

I don't know if this is the right Forum for this servlet PB.
Anyway .... Here goes !!!!

I am in the process of writing a servlet that generates an HTML page. My servlet draws a Financial Results HTML page. The page contains an image and a table with caption, heading and body. I have to have part of the table heading with a white font on a blue background and the rest of the table content with a black font on an alternating white and peach background for each row.

I tried different approaches such as using the FONT COLOR, BGCOLOR and different combinations but it does not give me the desired effect.

Any feedback is appreciated.

Thanks in advance,

Paolo
======
Here is my servlet source code:

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.text.*;
import java.util.*;
import helper.*;


public class FinancialDisplay extends HttpServlet {
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
String record;
BufferedReader file = new BufferedReader(new FileReader("C:\\Java Web\\Assignment 1\\financial.txt"));
record = file.readLine();
String[] fields;
int lineCnt = 0;
double calc = 0.0;
DecimalFormat dec = new DecimalFormat("#.##");
NumberFormat f = NumberFormat.getInstance(Locale.ENGLISH);
if (f instanceof DecimalFormat) {
((DecimalFormat) f).applyPattern("###,###,###.##;(###,###,###.##)");
((DecimalFormat) f).setDecimalSeparatorAlwaysShown(true);
}

out.println("<html><body text=\"black\"><center><img src=\"C:\\Java Web\\Assignment 1\\ugg.gif\"></img></center><br>");
out.println("<table cellspacing=\"0\"><caption><b>Financial Results</b><caption>");

while(record != null) {
fields = record.split(":");
if(fields.length == 3){
out.println("<FONT FACE=\"Comic Sans Ms, Times, Arial\" COLOR=\"#FFFFFF\" SIZE=\"small\">");
out.println("<tr bgcolor=\"blue\"><th></th><th align=\"right\">" + fields[0] +
"</th><th align=\"right\">" + fields[1] +
"</th><th align=\"right\">" + fields[2] + "</th><th rowspan=2><center>Growth</center></th></tr>");
out.println("<tr bgcolor=\"blue\"><th></th><th align=\"right\">12 Months</th><th align=\"right\">12 Months</th><th align=\"right\">12 Months</th><th></th></tr>");
//out.println("<font face=\"Arial\" color=\"black\">");
} else {
out.println("<FONT FACE=\"Comic Sans Ms, Times, Arial\" COLOR=\"#000000\" SIZE=\"small\">");
//out.println("<body text=\"black\">");
if(lineCnt % 2 == 0)
out.println("<tr bgcolor=#FFFFAA><th align=\"left\">");
else
out.println("<tr bgcolor=white><th align=\"left\">");
out.println("" + fields[0] +
"</th><th align=\"right\">" + "$" + f.format(Double.parseDouble(fields[1])) +
"</th><th align=\"right\">" + "$" + f.format(Double.parseDouble(fields[2])) +
"</th><th align=\"right\">" + "$" + f.format(Double.parseDouble(fields[3])) +
"</th><th align=\"right\">" + dec.format(100 * ((Double.parseDouble(fields[1]) - Double.parseDouble(fields[2])) / (Double.parseDouble(fields[1]) + Double.parseDouble(fields[3])))));
calc = 100 * ((Double.parseDouble(fields[1]) - Double.parseDouble(fields[2])) / (Double.parseDouble(fields[1]) + Double.parseDouble(fields[3])));
if(calc > 0) {
out.println("<img src=\"C:\\Java Web\\Assignment 1\\uparrow.gif\"></img>");
} else if(calc < 0) {
out.println("<img src=\"C:\\Java Web\\Assignment 1\\downarrow.gif\"></img>");
} else
out.println("<img src=\"C:\\Java Web\\Assignment 1\\tranparent.gif\"></img>");
out.println("</th></tr>");
}
record = file.readLine();
lineCnt++;
}
out.println("</small></body></table></html>");
}

public void doPost(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
doGet(request, response);
}

}

professorX
November 24th, 2003, 02:08 AM
try it:

out.println("<html><body><center><img src=\"C:\\Java Web\\Assignment 1\\ugg.gif\"></img></center><br>");
out.println("<table cellspacing=\"0\"><tr><td colspan="5"><b>Financial Results</b></td></tr>");

while(record != null) {
fields = record.split(":");
if(fields.length == 3){
out.println("<tr bgcolor=\"#0000FF\"><td></td><td align=\"right\" style=\"font-family: 'Comic Sans Ms', Times, Arial; color: #FFFFFF;\">" + fields[0] +
"</td><td align=\"right\" style=\"font-family: 'Comic Sans Ms', Times, Arial; color: #FFFFFF;\">" + fields[1] +
"</td><td align=\"right\" style=\"font-family: 'Comic Sans Ms', Times, Arial; color: #FFFFFF;\">" + fields[2] + "</td><td rowspan=2><center>Growth</center></td></tr>");
out.println("<tr bgcolor=\"#0000FF\"><td></td><td align=\"right\">12 Months</td><td align=\"right\">12 Months</td><td align=\"right\">12 Months</td><td></td></tr>");
//out.println("<font face=\"Arial\" color=\"black\">");
} else {
//out.println("<body text=\"black\">");
if(lineCnt % 2 == 0)
out.println("<tr bgcolor=#FFFFAA><td align=\"left\" style=\"font-family: 'Comic Sans Ms', Times, Arial; color: #000000; font-size: 10px;\">");
else
out.println("<tr bgcolor=white><td align=\"left\" style=\"font-family: 'Comic Sans Ms', Times, Arial; color: #000000; font-size: 10px;\">");
out.println("" + fields[0] +
"</td><td align=\"right\" style=\"font-family: 'Comic Sans Ms', Times, Arial; color: #000000; font-size: 10px;\">" + "$" + f.format(Double.parseDouble(fields[1])) +
"</th><th align=\"right\" style=\"font-family: 'Comic Sans Ms', Times, Arial; color: #000000; font-size: 10px;\">" + "$" + f.format(Double.parseDouble(fields[2])) +
"</td><td align=\"right\" style=\"font-family: 'Comic Sans Ms', Times, Arial; color: #000000; font-size: 10px;\">" + "$" + f.format(Double.parseDouble(fields[3])) +
"</td><td align=\"right\" style=\"font-family: 'Comic Sans Ms', Times, Arial; color: #000000; font-size: 10px;\">" + dec.format(100 * ((Double.parseDouble(fields[1]) - Double.parseDouble(fields[2])) / (Double.parseDouble(fields[1]) + Double.parseDouble(fields[3])))));
calc = 100 * ((Double.parseDouble(fields[1]) - Double.parseDouble(fields[2])) / (Double.parseDouble(fields[1]) + Double.parseDouble(fields[3])));
if(calc > 0) {
out.println("<img src=\"C:\\Java Web\\Assignment 1\\uparrow.gif\"></img>");
} else if(calc < 0) {
out.println("<img src=\"C:\\Java Web\\Assignment 1\\downarrow.gif\"></img>");
} else
out.println("<img src=\"C:\\Java Web\\Assignment 1\\tranparent.gif\"></img>");
out.println("</td></tr>");
}
record = file.readLine();
lineCnt++;
}
out.println("</small></table></body></html>");
}


You can to try use css-styles. For it You can create .css-file or use attribute "style" in tags... Here I use attribute "style":

<td align=\"right\" style=\"font-family: 'Comic Sans Ms', Times, Arial; color: #000000; font-size: 10px;\">

Also Your HTML-code was with errors... Hope, that now it is better.