H
H
Hello12015-11-21 13:39:48
Java
Hello1, 2015-11-21 13:39:48

Tomcat gives 404, how to make servlet work?

In idea, I created a new project "web application" called JEE Tutorial. web.xml was generated automatically

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
         version="3.1">
</web-app>

Further added servlet "com.example.tutorial.ServletExample", as a result such class
package com.example.tutorial turned out;
import .... 

@WebServlet(name = "ServletExample", urlPatterns = "/test")
public class ServletExample extends HttpServlet {

    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        PrintWriter out = response.getWriter();
        out.println("Hello Servlet!");
    }
}

But after starting tomcat 8, it gives 404 pages to all pages.
I tried to open /ServletExample/test, /test, /

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
goshan_p, 2015-11-21
@Hello1

Add to your Web.xml

<servlet>
    <servlet-name>*Имя сервлета*</servlet-name>
    <servlet-class>*Путь к сервлету(package)*</servlet-class>
</servlet>
<servlet-mapping>
    <servlet-name>*Имя сервлета*</servlet-name>
    <url-pattern>*Маппинг сервлета*</url-pattern>
</servlet-mapping>

and see how to properly configure Web.xml

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question