开发者

Java to C++ conversion of UI + logic + DB quering

开发者 https://www.devze.com 2023-02-18 18:51 出处:网络
I need some help in pointing me, how to convert* this code below to C++ <html><body> <table>

I need some help in pointing me, how to convert* this code below to 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* means write something similar - with mixed and messed up layers (this is actually all-in-1 layer)

But, to be honest, I want you to suggest m开发者_StackOverflow社区e some readings about data-access-layer and web interfaces in C++, because I have never done such things in C++, just some simple procedural / OOP

big thanks for any help


I hope this helps as an introduction to interpreting web scripting languages. JSP (and ASP and PHP) are actually "Inside-Out Code"[1]. They look like code embedded in text, but that is just an illusion......

  • <%=EXPRESSION%> becomes <%Response.Write(EXPRESSION)%>
  • <% STATEMENTS %> becomes "); STATEMENTS; Response.Write(@"
  • Prepend Response.Write(@" and Append ");

... And you have pretty much got your program.

So yours becomes:

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>");

Put like that, and with a littel bit of reformatting, you can see that it is actually a very simple program, and conversion should be equally simple.

The difficult bit will be converting things like the database access library.

[1] OK it is a little bit more complicated than that, but that's basically it. The JSP/PHP/ASP file goes through a preprocessor which converts all the directives to Java/VBScript/C#/Whatever, which will look much like what I show above. The result is recognisable as a bog-standard computer program which is then compiled/interpreted and run.

0

精彩评论

暂无评论...
验证码 换一张
取 消