I have a Song servlet that has some code and then sends the request to a songList.jsp and with this the titles of the songs are listed in a page. And this is working fine. But then, in the songList.jsp i defined a url for each song but when the url is clicked it is appearing:
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 where is the issue?
Song Servlet
@WebServlet(name ="Song", urlPatterns = {"/Song"})
// some code
request.setAttribute("result", result);
// some code then send the request
RequestDispatcher view=request.getRequestDispatcher("songList.jsp");
view.forward(request,response);
// songList.jsp
Im showing the song in the page and its woking ok
<c:forEach items="${result}" var="item" varStatus="status">
<a href="/SongPage?name=${item[0].replace(" ","+")}&id=${item[1]}">${item[0]}</a>
</h4>
<p class="card-text">${item[2]}</p>
</c:forEach>
This link should go to a page that shows info about a song, and have this format:
"http://localhost:8080/SongPage?name=Achtung&id=70"
But when is clicked appears the 404 error.
And then I have a SongPage servlet:
@WebServlet(name ="/SongPage", urlPatterns = {"/SongPage/name/*/id/*"})
public class SongPage extends HttpServlet {
public void init(){
System.out.println("Song Servlet");
}
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("+"," ");
String id = request.getParameter("id");
QueryManager qm = new QueryManager();
ArrayList<ArrayList<String>> result = qm.getSongInfo(name, id);
qm.closeConnections();
ArrayList<String> songInfo = result.get(0);
request.setAttribute("result", songInfo);
RequestDispatcher view=request.getRequestDispatcher("songPage.jsp");
view.forward(request,response);
}
Then I have the songPage.jsp but should not be important for the issue.