I am currently developing a web application in J2ee with a servlet and jsp, when I try to call a method I created in my servlet from a jsp I get a 404 error The requested resource is not available.
The problem comes from the url I show you the parts of the code that cause problems.
@WebServlet("/BookServlet")
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String action = request.getServletPath();
switch(action) {
case "/addBookForm":
addBookForm(request, response);
break;
case "/addBook" :
addBook(request, response);
break;
case "/updateBookForm" :
updateBookForm(request, response);
break;
case "/updateBook" :
updateBook(request, response);
break;
case "/deleteBook" :
deleteBook(request, response);
break;
case "/bookDetails" :
bookDetails(request, response);
break;
default:
listBook(request, response);
break;
}
}
The listBook method is well called.
In my jsp I put this
<a href="addBookForm" class="list-group-item">Ajouter un livre</a>
The problem is that when I click on add a book, the url is not good it gives me this : http://localhost:8080/Online_library/addBookForm
when normally it should give me http://localhost:8080/Online_library/BookServlet/addBookForm
And when I change this line @WebServlet("/BookServlet") in @WebServlet("/") the methods are called but I have another problem the images of my books are not displayed
Here is the line with the image :
<a href="bookDetails?idBook=<c:out value='${books.idBook}' />"><img src="${books.image}" style="width:100%; height:auto" class="img-thumbnail" ></a>
I think the problem comes from there @WebServlet but I'm not sure, if you have a little idea please share it