将您的数据库读取代码移至动作控制器。它应该从db中读取所需的值,并将其放入请求或模型中。
比使用jstl输出值(在jsp中):
<c:out value="${parameterFromRequest}"/>定义bean:
public class MyBean { private final String tName; private final String tFee; public MyBean(String tName, String tFee) { this.tName = tName; this.tFee = tFee; } public String getTName() { return tName; } public String getTFee() { return tFee; }}在动作控制器中创建集合:
String sql = "Select tname,tfee from addtest order by tname";ResultSet rs = SQLC.getData(sql, null);Collection<MyBean> myBeans = new ArrayList<MyBean>();while (rs.next()) { String testname = rs.getString("tname"); String testfee = rs.getString("tfee"); myBeans.add(new MyBean(testname, testfee));}request.setAttribute("myBeans", myBeans);在jsp中访问:
<c:forEach var="myBean" items="${myBeans}"> Name: <c:out value="${myBean.tName}"/> Fee: <c:out value="${myBean.tFee}"/></c:forEach>


