我正在编写一个web应用程序,它使用servlet来维护VideoData对象的ArrayList (这些对象只包含有关电影的基本信息,如标题、电影类型等)。
servlet将此列表放在请求的作用域中,并将请求和响应转发到一个jsp (此处仅显示了servlet代码的一部分):
public class VideoServlet extends HttpServlet {
private ArrayList<VideoData> library = new ArrayList<VideoData>();
public void doGet(HttpServletRequest request,
HttpServletResponse response) {
try {
// put ArrayList in Request's scope
request.setAttribute("the_table", library);
request.getRequestDispatcher("/listvideos.jsp").forward(request,
response);
...listvideos.jsp如下所示。我收到一个Tomcat错误,指出无法解析JSTL的uri。我已经在jsp代码的其他部分使用了EL,而不需要像这样有任何特殊的导入行,我不确定JSTL是否仍然是解决这类问题的首选方法,同时仍然尝试遵循MVC2并将所有Java代码保留在Servlet中。有谁能给我指个方向吗?理想情况下,如果可能的话,我想要一个纯EL解决方案。
<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN'
'http://www.w3.org/TR/html4/loose.dtd'>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>
<title>Cattle Drive Assignment Servlets-4: Videos</title>
</head>
<body>
<h1>Cattle Drive Assignment Servlets-4: Videos</h1>
<form method='post' action='/videos/VideoServlet'>
<a href="http://localhost:8080/videos/addvideo.jsp">Add a video</a>
<br>
<br>
<table border="1">
<tr>
<th>Title</th>
<th>Star</th>
<th>Type</th>
<th>VHS</th>
<th>DVD</th>
<th>Description</th>
</tr>
<c:forEach items="${the_table}" var="movie">
<tr>
<td>${movie.getTitle()}</td>
<td>${movie.getStar()}</td>
<td>${movie.getType()}</td>
<td>${movie.inVHS()}</td>
<td>${movie.inDVD()}</td>
<td>${movie.getDesc()}</td>
</tr>
</c:forEach>
</table>
</form>
</body>
</html>发布于 2011-05-27 13:38:06
您的代码看起来基本上是正确的。看起来您看到的错误表明在类路径中找不到JSTL标记库。请确保jstl.jar和standard.jar位于war的WEB-INF/lib文件夹中。
https://stackoverflow.com/questions/6148198
复制相似问题