我创建了下面的JSP页面来显示数据库中的itens列表,但是当我在容器tomcat7中运行应用程序时,我得到了一个空白页面:
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Lista de produtos</title>
</head>
<body>
<div id="display">
<table border=2>
<thead>
<tr>
<th>Model</th>
<th>Vendor</th>
<th>Price</th>
</tr>
</thead>
<tbody>
<c:forEach var="item" items="${list}">
<tr>
<td><c:out value="${item.model}"/></td>
<td><c:out value="${item.vendor}"/></td>
<td><c:out value="${item.price}"/></td>
</tr>
</c:forEach>
</tbody>
</table>
</div>
</body>
</html>此页面由servlet中的以下方法doGet触发:
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String parametro = request.getParameter("p");
List<equipment> lista = new ArrayList<equipment>();
if(parametro.equals("*")) {
try {
lista = FindAllItens();
} catch (ClassNotFoundException | SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
else {
try {
lista = FindItens(parametro);
} catch (ClassNotFoundException | SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
request.getSession().setAttribute("list", lista);
request.getRequestDispatcher("display.jsp").forward(request, response);
}有人有一个想法,什么可能是缺少的使该页工作?
发布于 2013-08-18 12:50:59
您忘记在页面顶部声明taglib的用法:
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>请始终查看生成的源代码,以查看实际生成的代码。您将在HTML中找到<c:out>,这表明JSP不将<c:out>识别为标记,而是将其识别为简单文本。
也就是说,如果您真的得到了一个完全空白的页面,那么您可能甚至没有执行这个JSP。您至少应该看到页面标题和表标题。
https://stackoverflow.com/questions/18299235
复制相似问题