【发布时间】:2014-02-09 14:10:41
【问题描述】:
我需要调用一个我不想使用 scriptlet 的类表单 jsp。我不确定在这里使用 tld 还是其他东西。我只是需要一个提示
所以在jsp中使用sciplets就像这样
<table width="99%" border="0" cellspacing="0" cellpadding="0">
<% sql= "select class,period,sub from timetable where uid='"+uid+"' " ;
rs = stmt.executeQuery(sql) ;
while (rs.next()) {
%>
<tr>
<td class="table_img"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="33%" height="19" class="notice_text"><div align="center"><%=rs.getString(2)%></div></td>
<td width="29%" class="notice_text"><div align="center"><%=rs.getString(1)%></div></td>
<td width="38%" class="notice_text"><div align="center"><%=rs.getString(3)%></div></td>
</tr>
</table></td>
</tr>
<% } %>
</table>
所以首先我创建了一个类和函数来获取这样的数据
public class TrHome extends ConnectionClass{
public List<TimeTablePojo> getTimeTableDetails(String scid, String uid){
Statement statement = getStatement();//getting connection form extended class
ResultSet resultSet = null;
String query = "select class,period,sub from timetable where uid='"+uid+"' " ;
List<TimeTablePojo> listPojo = new ArrayList<TimeTablePojo>();
try{
resultSet = statement.executeQuery(query);
while(resultSet.next()){
TimeTablePojo tPojo = new TimeTablePojo();
tPojo.setClas(resultSet.getString(1));
tPojo.setPeriod(resultSet.getInt(2));
tPojo.setSub(resultSet.getString(3));
listPojo.add(tPojo);
}
}catch(SQLException se){
System.err.println("sql exception in getTimeTableDetails(String scid, String uid) in TrHome.java : "+se);
}finally{
closeResultSet(resultSet);
closeConnection();//closing connection
}
return listPojo;
}
}
但是现在我不知道如何创建此类的对象并调用此函数以在 jsp 中获取数据。在获取数据后,我可以使用 jstl 对其进行迭代,但问题是如何调用此函数。根据我的理解,我必须创建 tld 。这是正确的还是有办法通过?我也不想在 servlet 的请求中设置数据。
【问题讨论】: