ฉันได้อ่านโพสต์มากมายที่สคริปต์เล็ตเป็นแนวทางปฏิบัติที่ไม่ดี ดังนั้นในที่สุดฉันก็ตัดสินใจหลีกเลี่ยงสิ่งนี้เช่นกัน ฉันได้พัฒนาโปรเจ็กต์โดยใช้เฟรมเวิร์ก struts ซึ่งหน้า jsp ส่วนใหญ่มีโค้ด java และตอนนี้ฉันต้องการลบโค้ดนั้นออกจากหน้าทั้งหมดของฉัน
<%@page import="java.sql.ResultSet"%>
<%@page import="com.pra.sql.SQLC"%>
<%@page import="java.util.ArrayList"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<table align="left" width="346" border="0">
<tr><td align="center" colspan="3" style="font-size:20px;">Tests We Provide</td></tr>
<tr>
<th width="80" height="38" nowrap>Test ID</th>
<th width="200" nowrap>Test Name</th>
<th width="144" nowrap>Test Fee</th>
</tr>
<%
String sql = "Select TestID,tname,tfee from addtest order by tname";
ResultSet rs = SQLC.getData(sql, null);
while (rs.next()) {
String testid = rs.getString("TestID");
String testname = rs.getString("tname");
String testfee = rs.getString("tfee");
%>
<tr>
<td width="80" height="34" nowrap><%=testid%></td>
<td width="200" nowrap><%=testname%></td>
<td width="144" nowrap><%=testfee%></td>
</tr>
<%
}
%>
</table>