I want to avoid scriptlets on my jsp pages. I have google it and search here too, but I could not solve it

I read a lot of posts that scriptlets are bad practice, so I decided to avoid this. I developed a project using struts framework, in which mostly jsp pages have Java code. And now I wanted to remove this code from all my pages.

<%@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>
+3
source share
2 answers
  • Associate a JSP with an action and therefore an Action class
  • Query execution in Java code - you can do it in Action, although I would recommend transferring control to a separate level of data access
  • Save the query results in a list of type bean that contains each of the columns in your result
  • , , .
+1

jsp JSTL. JSTL - , ( )

0

All Articles