0

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")) {
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • It is hard to reason about until you dont post the Controller code and what URL you are hitting. 404 normally means Bad Request, so i am guessing you hitting some wrong URL. – mdev Dec 02 '17 at 10:01
  • It's not enough stuffs to guess your error. But there is a url mapping issue, i thought. If you want to create a example like that, check it the post http://javabycode.com/java-frameworks/servlet-jsp/servlet-3-file-upload-example-using-multipartconfig.html – David Pham Dec 02 '17 at 10:10
  • i added context mapping information. – Alon Barak Dec 02 '17 at 11:26

1 Answers1

0

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.

Netanel Dadon
  • 58
  • 1
  • 1
  • 7