Issue
i have been tring to send a request to my configured servlet from my JSP file, but i keep getting error 404 - The requested resource is not available. i know that this question have been asked several times but it seems like none of the answer solved the problem for me. i'm using IntelliJ ide with tomcat 9 and Java maven project.
my servlet named ControllerServlet config is:
@WebServlet(name = "ControllerServlet", urlPatterns = {"/category", "/addToCart", "/viewCart","/updateCart", "/checkout", "/purchase"},loadOnStartup = 1)
my pom.xml file have those dependencies:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<dependencies>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>6.0.6</version>
</dependency>
</dependencies>
my project tree structure is like so:
pcstore
-src
-main
-java
-com
-pcStore
-controller
-ControllerServlet.java
-web
-WEB-INF
-view
-category.jsp
-web.xml
-index.jsp
-pom.xml
i was trying almost anything but ended up with no dice. my context root is /pcStore , and i hit pcStore/category?{id} this is part of the servlet, i just want to pile up too much unnessesary code:
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
//checks in which path the request is
String userPath = request.getServletPath();
// if category page is requested
if (userPath.equals("/category")) {
Solution
check if you have some collistions between your classpath jars and maven's. maybe you should try to copy the same project and try to run a sample servlet using module source without Maven or vice versa.
Answered By - Netanel Dadon