【发布时间】:2015-12-03 01:52:57
【问题描述】:
我是 Spring MVC 的新手,我想知道如何在我的 jsp 页面中从数据库中打印一个表。
我曾经使用 Java servlet 这样做:
<div class="alert alert-info" role="alert">
<span class="glyphicon glyphicon-ok" aria-hidden="true"></span>
<%
HashMap<String,Status> statusMap = new HashMap<String,Status>();
statusMap = AppUtils.getJobStatusLong();
DatabaseController db_controller = (DatabaseController)application.getAttribute("db_controller");
db_controller.openConnection();
out.print("<span> Today is "+AppUtils.getDate()+". You have " +db_controller.getClientNumber()+
" clients and "+db_controller.getJobNumber()+" jobs. </span>");
%>
</div>
但我听说在 Spring MVC 中视图和模型是严格分开的,所以通常我不应该在 JSP 中使用 Java 脚本?但是没有 Java scriptlet 怎么办呢?
谢谢。
【问题讨论】:
-
通常,不仅在 Spring 中,而且在任何基于 MVC 的架构中,都不应使用 scriplet。使用 JSTL 标签库。
标签: java jsp spring-mvc