0

I forked this Java Project and set up Tomcat 9 as usual. But, when I start the server running, I get HTTP Status 404.

Which part of my Tomcat / IntelliJ IDEA, do I have to update? I'm using IntelliJ Ultimate with Tomcat 9 and 10 (both installed, but using 9) on macOS - MacBook Air (M1, 2020).

Here are some relevant screenshots from my project:

  1. Tomcat Server enter image description here

  2. Tomcat Deployment enter image description here

  3. Browser enter image description here

  4. Artifact enter image description here

  5. pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<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>

    <groupId>com.example</groupId>
    <artifactId>filter</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>war</packaging>

    <properties>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
        <junit.version>5.8.2</junit.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>4.0.1</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>jstl</groupId>
            <artifactId>jstl</artifactId>
            <version>1.2</version>
        </dependency>
        <dependency>
            <groupId>javax.servlet.jsp</groupId>
            <artifactId>javax.servlet.jsp-api</artifactId>
            <version>2.3.3</version>
            <scope>compile</scope>
        </dependency>
             
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-api</artifactId>
            <version>${junit.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-engine</artifactId>
            <version>${junit.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-core</artifactId>
            <version>3.12.4</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-junit-jupiter</artifactId>
            <version>3.12.4</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <artifactId>maven-clean-plugin</artifactId>
                <version>3.1.0</version>
            </plugin>
            <!-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_war_packaging -->
            <plugin>
                <artifactId>maven-resources-plugin</artifactId>
                <version>3.0.2</version>
            </plugin>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.0</version>
            </plugin>
            <plugin>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.22.1</version>
                <configuration>
                    <includes>
                        <include>**/*Test.java</include>
                    </includes>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-war-plugin</artifactId>
                <version>3.2.2</version>
            </plugin>
            <plugin>
                <artifactId>maven-install-plugin</artifactId>
                <version>2.5.2</version>
            </plugin>
            <plugin>
                <artifactId>maven-deploy-plugin</artifactId>
                <version>2.8.2</version>
            </plugin>
        </plugins>
    </build>
</project>

Sarvar Khalimov
  • 455
  • 5
  • 11
  • 1
    That means Tomcat is running, and the URL you're hitting doesn't exist. Seems more like a web app config/code issue than a Tomcat issue so far. – Dave Newton Feb 10 '23 at 03:07
  • I see. So, what would you advise me to check / update? – Sarvar Khalimov Feb 10 '23 at 03:16
  • Your web app config and code? – Dave Newton Feb 10 '23 at 03:16
  • Here is my web config [web.xml]: Archetype Created Web Application – Sarvar Khalimov Feb 10 '23 at 03:19
  • (1) Your picture Screen 2, Tomcat - Deployment **Application context** , is empty, set **Application context:** value **filter**, (2) browser, open `http://localhost:8080/filter` – life888888 Feb 10 '23 at 03:30
  • @life888888 I added `/filter` into Application context field, but still getting 404 – Sarvar Khalimov Feb 10 '23 at 03:36
  • by default, there was `/filter_war_exploded`, but I had removed it to land directly on the home page – Sarvar Khalimov Feb 10 '23 at 03:39
  • 1
    By default, when you deployment `XXX.war` to tomcat, application context will be `XXX`, mapping to url , will be `http://localhost:8080/XXX`. application context `/` will mapping to `http://localhost:8080/`, application context `/` default is for Tomcat Root, – life888888 Feb 10 '23 at 03:49
  • 1
    Your browser error message have `The requestd resource [/login] is not available`. You need check this request `/login` is come from your code, or come from tomcat config? – life888888 Feb 10 '23 at 03:55

2 Answers2

2

In your forked sample project's src/main/webapp/index.jsp file, it contains this part:

<jsp:forward page="/login"/>

Actually, you have already accessed the index page successfully, and it redirects to the /login page which does not exist in your project so 404 here.

But you have an src/main/webapp/login.jsp file in this project, so you could access the http://localhost:8080/xxxx/login.jsp.

If you change the <jsp:forward page="/login"/> to <jsp:forward page="/login.jsp"/>, it would help too.

LJ replica
  • 451
  • 6
  • Indeed, I have been successfully accessing the `index.jsp`. I just checked my server again by replacing forwarding in `index.jsp` with with something like `Hello world` text and the browser returned this text. I am a total newbie in Java Servlets – Sarvar Khalimov Feb 10 '23 at 04:08
0

Adding "/" (slash) to the Application context in the deployment tab should do it.

If that doesn't solve it, then go to this page.

Sendi
  • 11
  • 2