user3438791
user3438791

Reputation: 89

Display table in HTML within java

I am able to display the table but the headers are bit misaligned and shifted to right. Can someone suggest what can be missing here.

Current o/p: (Header are misaligned)

                Server  name ID
S1 ABC 43
S2 XYZ 67

Code:

out.append("<table id=\"dtable\" class=\"tablesorter\">");
out.append("<thead>");
out.append("<tr>");
out.append("<th>Server</th>");
out.append("<th>name</th>");
out.append("<th>ID</th>");
out.append("</tr>");
out.append("</thead>");
out.append("<tbody>");

for (String s : returns) {
  String[] s2=s.split("-");

  out.append("<tr>");
  out.append("<td>");
  for(String results : s2)
  {

    out.append(results);
    out.append("&nbsp;");
  }
  out.append("</td>");
  out.append("</tr>");
} 

out.append("</table>");

Upvotes: 2

Views: 257

Answers (2)

Zakaria Acharki
Zakaria Acharki

Reputation: 67505

Try to add every string to separated column td like :

for (String s : returns) {
    String[] s2=s.split("-");

    out.append("<tr>");
    for(String results : s2)
    {
        out.append("<td>");
        out.append(results);
        out.append("&nbsp;");
        out.append("</td>");
    }
    out.append("</tr>");
} 

Hope this helps.

Upvotes: 1

Joaquin Peraza
Joaquin Peraza

Reputation: 343

Here your creating a row and closing it “s2” times please check this:

    out.append("<tr>");
    out.append("<td>");
    for (String results : s2) {

        out.append(results);
        out.append("&nbsp;");
    }
    out.append("</td>");
    out.append("</tr>");
}

And there is no tbody close tag

Upvotes: 1

Related Questions