2

When I access "http://localhost:8080/project/Song", dont appears any error, it works it lists some songs in the page. When I click on a song I go to a URL "http://localhost:8080/SongPage?name=A+Tribe&id=201" but here it appears a 404 error, maybe because the url has parameters, accessing this URL appears an error:

HTTP Status 404 – Not Found

Description The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.

Do you know why?

Maybe its because of this urlPattern below:

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

I have this servlet below:

@WebServlet(name ="Song", urlPatterns = {"/Song"})
public class Song extends HttpServlet {

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        QueryManager qm = new QueryManager();
        ArrayList<ArrayList<String>> result = qm.Songs();
        qm.closeConnections();

        request.setAttribute("result", result.get(0));
        request.setAttribute("id", result.get(1));
        RequestDispatcher view=request.getRequestDispatcher("songList.jsp");
        view.forward(request,response);    

    }
}

In songList.jsp i have this:

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

SongPage.java:

@WebServlet(name ="SongPage", urlPatterns = {"/SongPage"})
public class SongPage extends HttpServlet {

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String name = request.getParameter("name").replace("+"," ");

    ...
 }

1 Answer 1

2

Your original url "http://localhost:8080/project/Song" has "project" as base path but the other url "http://localhost:8080/SongPage?name=A+Tribe&id=201" does not have that path. Most likely you need to update your JSP to include it in the "href" tag as a quick fix:

<a href="project/SongPage?name=${result[status.index].replace(" ","+")}&id=${id[status.index]}"> ${result[status.index]} </a> <br />

or most likely if it is actually a context path:

<a href="${pageContext.request.contextPath}/SongPage?name=${result[status.index].replace(" ","+")}&id=${id[status.index]}"> ${result[status.index]} </a> <br />

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.