我有一个具有以下结构的 netbeans 项目。当我访问 localhost:8080/Project/Song 时出现错误:
HTTP 状态 404
描述:源服务器未找到目标资源的当前表示。
您知道问题出在哪里以及如何解决吗?
项目结构:
Project
Web Pages
META-INF
WEB-INF
web.xml
lib
jstl-1.2.jar
songs.jsp
Source Packages
data
Song.java
Song.java:
package data;
import org.apache.jena.base.Sys;
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 java.io.IOException;
import java.util.ArrayList;
@WebServlet(name = "/Song")
public class Song extends HttpServlet {
/*protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
}*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
QueryManager qm = new QueryManager();
ArrayList<ArrayList<String>> result = qm.getSongs();
qm.closeConnections();
request.setAttribute("result", result.get(0));
request.setAttribute("id", result.get(1));
RequestDispatcher view=request.getRequestDispatcher("songs.jsp");
view.forward(request,response);
}
public void init(){
System.out.println("Songs page");
}
}
歌曲.jsp:
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>
<link href="style.css" rel="stylesheet">
<title>Songs List</title>
</head>
<body>
<div id="songs">
<c:forEach items="${result}" var="item" varStatus="status">
<a href="/SongPage?name=${result[status.index].replace(" ","+")}&id=${id[status.index]}"> ${result[status.index]} </a> <br />
</c:forEach>
</div>
</body>
</html>
网络 xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
<servlet>
<servlet-name>Song</servlet-name>
<servlet-class>Song</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Song</servlet-name>
<url-pattern>/Song</url-pattern>
</servlet-mapping>
最佳答案
您正在使用两种 servlet 映射方法。使用其中之一。 注释方法或 web.xml 从 web.xml 文件中删除 servlet 映射。表示删除下面的部分
<servlet>
<servlet-name>Song</servlet-name>
<servlet-class>Song</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Song</servlet-name>
<url-pattern>/Song</url-pattern>
</servlet-mapping>
以下行无效。您需要提供您类(class)的完全限定名称。无论如何,如果你有 annotation
<servlet-class>Song</servlet-class>
使用这个。
@WebServlet(name = "Song", urlPatterns = {"/Song"})
关于java - 错误状态 404 : origin server did not find a current representation,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47759480/