我有一个 .jsp 文件和一个 .java 文件。我尝试使用注释,但两个文件似乎没有连接。
这是Java代码
@WebServlet("/WEB-INF/JSP/restaurant.htm")
public class restaurant extends HttpServlet{
private static final long serialVersionUID = 1L;
private static final String VIEW = "/WEB-INF/JSP/restaurant.jsp";
private RestaurantService restaurantService = new RestaurantService();
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
List<Restaurant> restaurants = restaurantService.findAll();
request.setAttribute("restaurants", restaurants);
request.getRequestDispatcher(VIEW).forward(request, response);
}
这是我的 JSP 代码
<%@page contentType="text/html" pageEncoding="UTF-8" session="false"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<c:set var="contextPath" value="${pageContext.servletContext.contextPath}" />
<!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=ISO-8859-1">
<title>Selecteer uw restaurant</title>
</head>
<body>
<h1>Selecteer uw restaurant</h1>
<c:forEach var="restaurant" items="${restaurants}">
<c:url value="/gerechten" var="restaurantURL">
<c:param name="rest">${restuarant.restaurantId}</c:param>
</c:url>
<a href="restaurantURL"> <img alt="${restaurant.naam}"
src="${restaurant.image}"> <br /> ${restaurant.naam}
</a><br/><br/>
</c:forEach>
</body>
</html>
它只有几行,但即使这样也行不通。我是否使用 web.xml 如果是,我该如何使用它?
提前致谢!