请在回答之前阅读.这是我梦寐以求的幻想编程技巧.我想知道现实生活中是否有任何接近的东西.
以下JSP页面:
<%
html {
head {
title {"Pure fantasy";}
}
body {
h1 {"A heading with double quote (\") character";}
p {"a paragraph";}
String s = "a paragraph in string. the date is ";
p {
s;
new Date().toString();
}
table (Border.ZERO, new Padding(27)) {
tr {
for (int i = 0; i < 10; i++) {
td {i;}
}
}
}
}
}
%>
Run Code Online (Sandbox Code Playgroud)
可以生成以下HTML页面:
<html>
<head>
<title>Pure fantasy</title>
</head>
<body>
<h1>A heading with double quote (") character</h1>
<p>a paragraph</p>
<p>a paragraph in string. the date is 11 December 2012</p>
<table border="0" padding="27">
<tr>
<td>0</td>
<td>1</td>
<td>2</td>
<td>3</td>
<td>4</td>
<td>5</td>
<td>6</td>
<td>7</td>
<td>8</td>
<td>9</td>
</tr>
</table>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
关于这个幻想的事情是它重新使用老一套的Java编程语言技术,它能够在类似的方式使用自定义的关键字if-else-then,while,try-catch等来表示,可以很容易的语法正确性检查非HTML方式html标签,以及最重要的可以轻松地与常规的Java代码混合起来没有的海洋丢失<%,%>,<%=,out.write(),等.
一个附加功能是可以直接将字符串作为命令放置到生成的HTML中,这是Java不支持的(在使用之前必须将纯字符串分配给变量).
PS:我知道你可以使用HTML库来使用Java代码构建HTML,但是这些库的问题是,源代码本身没有像上面代码那样可读的HTML表示 - 如果你理解我的意思.
| 归档时间: |
|
| 查看次数: |
1372 次 |
| 最近记录: |