OzzyW
OzzyW

Reputation: 117

Error status 404: origin server did not find a current representation

I have a netbeans Project with the structure below. When i access localhost:8080/Project/Song it appears the error:

HTTP status 404

Description: The origin server did not find a current representation for the target resource.

Do you know how where is the issue and how to correct it?

Project structure:

 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");
    }
}

songs.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>

web 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>

Upvotes: 1

Views: 1530

Answers (1)

Vishnu T S
Vishnu T S

Reputation: 3914

You are using both servlet mapping methods. Use one of them. Annotation method or web.xml Remove servlet mapping from web.xml file. Means remove below portion

<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>

The below line is not valid. You need to give the fully qualified name of your class. anyway you dont need this if you have annotation

<servlet-class>Song</servlet-class>

use this.

  @WebServlet(name = "Song", urlPatterns = {"/Song"})

Upvotes: 2

Related Questions