私はJavaを初めて使い、HTML/CSSとJavascriptをJavaコードに埋め込むことに取り掛かりました。 私のコードをビルドするのに役立つポインタがあります。私は私のJavaコードを書くためにEclipseエディタを使用しています。IDEのEclipseを使用してJavaコードでHTML、CSS、およびJavascriptを使用する
私は、以下のように私のJavaコードにHTML表示のいくつかの部分を表示することができましたが、html/css/javascriptでテーブルの並べ替えを達成しようとしています。
は以下を下回っており、正常に動作として貼り付けることができますHTML/CSS/JavaScriptのである私のdisplay.javaファイル
public void transformForRequestSuccessful(MarkupOutput out) {
//Call render methods
renderdisplay(out);
}
public void renderdisplay(MarkupOutput out)
{
out.append("<BR/>");
out.append("<p>Look at the body!</p>");
out.append("<BR/>");
}
です。
このHTMLファイルをsort.htmlとして保存しました。独立して呼び出されたときに正常に動作します。
html>
<head>
<meta http-equiv="content-type" content="text/html;charset=Windows-1252">
<script type="text/javascript">
var people, asc1 = 1,
asc2 = 1,
asc3 = 1;
window.onload = function() {
people = document.getElementById("people");
}
function sort_table(tbody, col, asc) {
var rows = tbody.rows,
rlen = rows.length,
arr = new Array(),
i, j, cells, clen;
// fill the array with values from the table
for (i = 0; i < rlen; i++) {
cells = rows[i].cells;
clen = cells.length;
arr[i] = new Array();
for (j = 0; j < clen; j++) {
arr[i][j] = cells[j].innerHTML;
}
}
// sort the array by the specified column number (col) and order
(asc)
arr.sort(function (a, b) {
return (a[col] == b[col]) ? 0 : ((a[col] > b[col]) ? asc : -1 *
asc);
});
// replace existing rows with new rows created from the sorted array
for (i = 0; i < rlen; i++) {
rows[i].innerHTML = "<td>" + arr[i].join("</td><td>") + "</td>";
}
}
</script>
<style type="text/css">
table {
border-collapse: collapse;
border: none;
}
th,
td {
border: 1px solid black;
padding: 4px 16px;
font-family: Times New Roman;
font-size: 15px;
text-align: left;
}
th {
background-color: #C8C8C8;
cursor: pointer;
}
</style>
</head>
<body>
<table>
<thead>
<tr>
<th onclick="sort_table(people, 0, asc1); asc1 *= -1; asc2 = 1;
asc3 = 1;">ServerName</th>
<th onclick="sort_table(people, 1, asc2); asc2 *= -1; asc3 = 1;
asc1 = 1;">UserName</th>
<th onclick="sort_table(people, 2, asc3); asc3 *= -1; asc1 = 1;
asc2 = 1;">JobId</th>
</tr>
</thead>
<tbody id="people">
<tr>
<td>Server1</td>
<td>ABC</td>
<td>18</td>
</tr>
<tr>
<td>Server2</td>
<td>XYZ</td>
<td>20</td>
</tr>
</tbody>
</table>
</body>
</html>
これをJavaコードに埋め込む方法は参考になります。 私は、基本的なJavaプログラミングに慣れ親しんだり、気づかなかったりすると謝ります。
おかげ
ありがとうございます。私はasp.netを使用しています。 ASPのサンプルサンプルを投稿できますか? – user3438791
しかし、あなたはJavaコードを求めます。どのようにasp.netにJavaコードを埋め込むことができますか?あなたの質問を明確にしてください –
私は私のウェブサーバーとしてIISを使用していたことを意味しました。私が達成しようとしているのは、この投稿のhttps://stackoverflow.com/questions/15842683/string-builder-into-html-table-formatと似ていますが、私はcssとjsで使用されている特別な文字をエスケープできません。そのためには助けが必要です。 – user3438791