我在使用列表对象列表填写jsp中的表时遇到问题。我似乎无法弄清楚我做错了什么,因为我看到它会告诉我按照我的方式去做。
这是我的jsp表:
<table id="budgetTbl" action="" method="post" class="table table-striped table-bordered table-hover">
<thead>
<tr>
<th>Budget</th>
<th>Projected</th>
<th>Actual</th>
</tr>
</thead>
<tbody>
<c:forEach var="budget" items="${budgets}">
<tr>
<td>${budget.budgetName}</td>
<td>${budget.budgetAmount}</td>
<td>${budget.actual}</td>
</tr>
</c:forEach>
</tbody>
</table>
这是我的控制器中的代码:
@RequestMapping(value="budget" , method = RequestMethod.GET)
public String getBudget(@ModelAttribute("user") User user, Model model) {
List<Budget> budgets = budgetService.getBudgets(1);
model.addAttribute("budgets", budgets);
if(user.getLoggedIn())
return "budget";
else
return "redirect:login.html";
}
我的豆子:
<jsp:useBean id="budget" class="com.lindeman.model.Budget"/>
<jsp:setProperty name="budget" property="*"/>
budgetService:
@Service("budgetService")
public class BudgetServiceImpl implements BudgetService {
public List<Budget> getBudgets(int dateID) {
List<Budget> budgets = new ArrayList<Budget>();
try (CachedRowSet bud = DAO.getAllBudgets(dateID)) {
bud.beforeFirst();
while(bud.next()){
Budget budget = new Budget();
budget.setBudgetID(bud.getInt("BudgetID"));
budget.setDateID(bud.getInt("DateID"));
budget.setBudgetName(bud.getString("BudgetName"));
budget.setBudgetAmount(bud.getDouble("BudgetAmount"));
budget.setActual(bud.getDouble("Actual"));
budgets.add(budget);
}
} catch (SQLException e) {
DataDriver.processException(e);
}
return budgets;
}
}
答案 0 :(得分:0)
你缺少taglib导入,把它放在jsp的顶部
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>