我需要一些帮助来指导我,如何将下面的代码转换*为C++
<html><body>
<table>
<%
while( rs.next() ){
%><tr>
<td><%=rs.getString("id") %></td>
<td><%=rs.getString("date") %></td>
<td><%=rs.getString("email") %></td>
</tr>
<%}%>
<%}
catch(Exception e){e.printStackTrace();}
finally{
if(con!=null) con.close();
}
%>
</body></html>
convert* 意味着写一些类似的东西 - 混合和困惑的层(这实际上是 all-in-1 层)
但是,老实说,我希望你建议我阅读一些关于 C++ 中的数据访问层和 Web 接口(interface)的读物,因为我从来没有在 C++ 中做过这些事情,只是一些简单的过程/OOP
非常感谢您的帮助
最佳答案
我希望这有助于介绍解释网络脚本语言。 JSP(以及 ASP 和 PHP)实际上是“由内而外的代码”[1]。它们看起来像是嵌入在文本中的代码,但这只是一种错觉……
-
<%=EXPRESSION%>
变成<%Response.Write(EXPRESSION)%>
-
<% STATEMENTS %>
变成"); STATEMENTS; Response.Write(@"
- 前置
Response.Write(@"
并附加");
...您的程序已经差不多完成了。
所以你的变成了:
Response.Write(@"
<html><body>
<table>
");try{
while( rs.next() ){
Response.Write(@"<tr>
<td>"); Response.Write(rs.getString("id")); Response.Write(@"</td>
<td>"); Response.Write(rs.getString("date")); Response.Write(@"</td>
<td>"); Response.Write(rs.getString("date")); Response.Write(@"</td>
</tr>
");}Response.Write(@"
");}
catch(Exception e){e.printStackTrace();}
finally{
if(con!=null) con.close();
}
Response.Write(@"
</body></html>");
这样放,稍加格式化,你会发现它其实是一个非常简单的程序,转换也应该同样简单。
困难的一点是转换诸如数据库访问库之类的东西。
[1] 好吧,它比那复杂一点,但基本上就是这样。 JSP/PHP/ASP 文件通过预处理器将所有指令转换为 Java/VBScript/C#/Whatever,这看起来很像我上面显示的内容。结果被识别为沼泽标准计算机程序,然后被编译/解释和运行。
关于UI + 逻辑 + DB 查询的 Java 到 C++ 转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5352715/