Stack Exchange
Java Servlet - HTTP Status 404
Здравствуйте. Есть простой сервлет, который не хочет работать. Создал я его в Intelij Idea, при помощи Maven. Но при попытке загрузки через поисковую строку (http://localhost:8083 или http://127.0.0.1:8083) в браузере выдает:
HTTP Status 404 - /mypage.jsp

type Status report

message /mypage.jsp

description The requested resource is not available.

Apache Tomcat/9.0.0.M11

Вот сам код (MainServlet.class):
package Servlet;

/**
 * Created by Alex on 28.10.2016.
 */
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/")
public class MainServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {

        req.setAttribute("name", "Test");

        req.getRequestDispatcher("mypage.jsp").forward(req, resp);

    }

}

mypage.js:
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Devcolibri.com</title>
</head>
<body>
<h1>Hello ${name}</h1>
</body>
</html>

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>ServerKotin</groupId>
    <artifactId>ServerKotin</artifactId>
    <version>1.0-SNAPSHOT</version>

    <dependencies>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>3.1.0</version>
        </dependency>
    </dependencies>

    <build>
    <plugins>
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-war-plugin</artifactId>
        <version>2.1.1</version>
        <configuration>
            <failOnMissingWebXml>false</failOnMissingWebXml>
        </configuration>
    </plugin>
    </plugins>
    </build>

Дерево проекта:

Конфигурация проекта:

Прилаживаю также логи с Intelij - все нормально, нет ексепшенов:
C:\Server\TOMCAT_HOME\bin\catalina.bat run
[2016-10-29 02:13:40,992] Artifact ServerKotin:Web exploded: Server is not connected. Deploy is not available.
Using CATALINA_BASE:   "C:\Users\Alex\.IntelliJIdea2016.2\system\tomcat\Unnamed_ServerKotin"
Using CATALINA_HOME:   "C:\Server\TOMCAT_HOME"
Using CATALINA_TMPDIR: "C:\Server\TOMCAT_HOME\temp"
Using JRE_HOME:        "C:\Program Files\Java\jdk1.8.0_74"
Using CLASSPATH:       "C:\Server\TOMCAT_HOME\bin\bootstrap.jar;C:\Server\TOMCAT_HOME\bin\tomcat-juli.jar"
29-Oct-2016 02:13:42.545 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server version:        Apache Tomcat/9.0.0.M11
29-Oct-2016 02:13:42.545 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server built:          Oct 6 2016 18:54:10 UTC
29-Oct-2016 02:13:42.561 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server number:         9.0.0.0
29-Oct-2016 02:13:42.561 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Name:               Windows 8.1
29-Oct-2016 02:13:42.561 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Version:            6.3
29-Oct-2016 02:13:42.561 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Architecture:          amd64
29-Oct-2016 02:13:42.561 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Java Home:             C:\Program Files\Java\jdk1.8.0_74\jre
29-Oct-2016 02:13:42.561 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Version:           1.8.0_74-b02
29-Oct-2016 02:13:42.561 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Vendor:            Oracle Corporation
29-Oct-2016 02:13:42.561 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_BASE:         C:\Users\Alex\.IntelliJIdea2016.2\system\tomcat\Unnamed_ServerKotin
29-Oct-2016 02:13:42.561 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_HOME:         C:\Server\TOMCAT_HOME
29-Oct-2016 02:13:42.561 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcom.sun.management.jmxremote=
29-Oct-2016 02:13:42.561 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcom.sun.management.jmxremote.port=1009
29-Oct-2016 02:13:42.561 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcom.sun.management.jmxremote.ssl=false
29-Oct-2016 02:13:42.561 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcom.sun.management.jmxremote.authenticate=false
29-Oct-2016 02:13:42.561 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.rmi.server.hostname=127.0.0.1
29-Oct-2016 02:13:42.561 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djdk.tls.ephemeralDHKeySize=2048
29-Oct-2016 02:13:42.561 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.protocol.handler.pkgs=org.apache.catalina.webresources
29-Oct-2016 02:13:42.561 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.config.file=C:\Users\Alex\.IntelliJIdea2016.2\system\tomcat\Unnamed_ServerKotin\conf\logging.properties
29-Oct-2016 02:13:42.561 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
29-Oct-2016 02:13:42.561 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.base=C:\Users\Alex\.IntelliJIdea2016.2\system\tomcat\Unnamed_ServerKotin
29-Oct-2016 02:13:42.561 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.home=C:\Server\TOMCAT_HOME
29-Oct-2016 02:13:42.561 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.io.tmpdir=C:\Server\TOMCAT_HOME\temp
29-Oct-2016 02:13:42.561 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent Loaded APR based Apache Tomcat Native library 1.2.10 using APR version 1.5.2.
29-Oct-2016 02:13:42.561 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent APR capabilities: IPv6 [true], sendfile [true], accept filters [false], random [true].
29-Oct-2016 02:13:42.561 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent APR/OpenSSL configuration: useAprConnector [false], useOpenSSL [true]
29-Oct-2016 02:13:43.601 INFO [main] org.apache.catalina.core.AprLifecycleListener.initializeSSL OpenSSL successfully initialized (OpenSSL 1.0.2j  26 Sep 2016)
29-Oct-2016 02:13:43.754 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["http-nio-8083"]
29-Oct-2016 02:13:43.769 INFO [main] org.apache.tomcat.util.net.NioSelectorPool.getSharedSelector Using a shared selector for servlet write/read
29-Oct-2016 02:13:43.769 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["ajp-nio-1099"]
29-Oct-2016 02:13:43.785 INFO [main] org.apache.tomcat.util.net.NioSelectorPool.getSharedSelector Using a shared selector for servlet write/read
29-Oct-2016 02:13:43.785 INFO [main] org.apache.catalina.startup.Catalina.load Initialization processed in 1628 ms
29-Oct-2016 02:13:43.802 INFO [main] org.apache.catalina.core.StandardService.startInternal Starting service Catalina
29-Oct-2016 02:13:43.802 INFO [main] org.apache.catalina.core.StandardEngine.startInternal Starting Servlet Engine: Apache Tomcat/9.0.0.M11
29-Oct-2016 02:13:43.819 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler [http-nio-8083]
29-Oct-2016 02:13:43.838 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler [ajp-nio-1099]
29-Oct-2016 02:13:43.842 INFO [main] org.apache.catalina.startup.Catalina.start Server startup in 56 ms
Connected to server
[2016-10-29 02:13:44,250] Artifact ServerKotin:Web exploded: Artifact is being deployed, please wait...
[2016-10-29 02:13:44,810] Artifact ServerKotin:Web exploded: Artifact is deployed successfully
[2016-10-29 02:13:44,810] Artifact ServerKotin:Web exploded: Deploy took 560 milliseconds
29-Oct-2016 02:13:53.827 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory C:\Server\TOMCAT_HOME\webapps\manager
29-Oct-2016 02:13:53.874 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory C:\Server\TOMCAT_HOME\webapps\manager has finished in 31 ms

В чем ошибка, почему оно не работает?

Неправильная папка сконфигурирована как корень веб-приложения - судя по скриншоту, сейчас это web, а должно быть src/main/webapp. Пере-импортируйте проект из maven, должно помочь (можно поменять вручную в Idea, но это будет не совсем правильно).
UPD: сразу не заметил, вам нужно ещё добавить <packaging>war</packaging> в pom.xml внутри <project>, иначе сейчас у вас проект имеет тип jar, т.е. это не web-проект.

Вообщем пытался реимпортить мавен проект - ничего не поменялось, тогда просто перенес mypage.jsp в папку web. Спасибо за помощь. Хотя хотелось бы еще уточнить, если другой способ сделать папку webapp корнем веб приложения?

@Alex Я обновил ответ, попробуйте импортировать с изменённым pom.xml. Другой способ есть, надо идти в Project Structure, там слева выбрать Modules, в дереве выбрать Web и там менять пути.

Все заработало, спасибо большое!)
