Hello. There is a simple servlet that does not want to work. I created it in Intelij Idea, with the help of Maven. But when you try to download via the search box ( http: // localhost: 8083 or http://127.0.0.1:8083 ) in the browser, it gives:

HTTP Status 404 - /mypage.jsp type Status report message /mypage.jsp description The requested resource is not available. Apache Tomcat/9.0.0.M11 

Here is the code itself (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> 

Project Tree:

enter image description here

Project Configuration: enter image description here

I also attach logs with Intelij - everything is fine, there are no exceptions:

 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 

What is the mistake, why is it not working?

    1 answer 1

    The wrong folder is configured as the root of the web application - judging by the screenshot, now it is a web , and it should be src/main/webapp . Re-import the project from maven should help (you can change it manually in Idea, but this will not be entirely correct).

    UPD: didn’t notice right away, you need to add <packaging>war</packaging> to pom.xml inside <project> , otherwise your project now has a jar type, i.e. This is not a web project.

    • In general, I tried to reimport the maven project - nothing has changed, then I just transferred mypage.jsp to the web folder. Thanks for the help. Although I would like to clarify if another way to make the webapp folder the root of a web application? - Alex
    • @Alex I updated the answer, try importing with the modified pom.xml . There is another way, you have to go to the Project Structure, select Modules on the left, select Web in the tree and change paths there. - Roman
    • Everything worked, thank you very much!) - Alex