我第一次发贴!因此,我目前正在学校中创建一个Java Web项目,该项目具有包含艺术家,专辑和曲目的sqlite数据库。我正在尝试将所有艺术家列出到网页中。问题是我不断收到404错误。我的jsp文件是在我的老师指导下的WebContent / WEB-INF / views中。我也认为我的servlet出了点问题。 这是我的servlet:
package javaweb.part1.control;
import java.io.IOException;
import java.sql.SQLException;
import java.util.List;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import levykauppa.Artist;
import levykauppa.ArtistDAO;
@WebServlet("/artist")
public class ArtistServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
private ArtistDAO artistDao = new ArtistDAO();
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
List<Artist> artists = null;
try {
artists = artistDao.findAllArtists();
} catch (SQLException e) {
e.printStackTrace();
}
request.setAttribute("artist", artists);
RequestDispatcher dispatcher =
request.getRequestDispatcher("levykauppa/WebContent/WEB-
INF/views/artistlist.jsp");
dispatcher.include(request, response);
}
}
这是我的jsp文件:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>artist</title>
</head>
<body>
<c:forEach items="${ artists }" var="artist">
<c:out value="${ artist.getName() }" />
</c:forEach>
</body>
</html>