0

I'm new and following a HelloWorld project in Eclipse that just added a servlet (I'm using Eclipse Neon w/ Tomcat 9). When I run on server, I get the below errors. There is not any issues connecting to index.html, just the servlet! Below are screen shots, let me know if I need to provide more info -Thx

404Error[1]
servlet[2]
webxml[3]
indexhtml[4]
Will R
  • 11
  • 1

1 Answers1

1

Most likely the web container can't find your servlet.

A web container is the component of a web server that interacts with Java servlets.

  • A web container is responsible for managing the lifecycle of servlets.
  • Mapping a URL to a particular servlet.

  • Ensuring that the URL requester has the correct access-rights.

You can configure your servlet in web.xml

<servlet>
  <servlet-name>servletName</servlet-name>
  <servlet-class>packageName.servletName</servlet-class>
</servlet>

<servlet-mapping>
  <servlet-name>servletName</servlet-name>
  <url-pattern>/yourServletUrl</url-pattern>
</servlet-mapping>

or you can use annotations since servlets 3.0.

import javax.servlet.annotation.WebServlet;

@WebServlet(name = "servletName", urlPatterns = { "/yourServletUrl" })
public class servletName extends HttpServlet {

It is easier and more readable.

Your url should be

localhost:8080/YourProjectName/YourServletUrl

Also i have some memories that Eclipse Neon don't work very well with JavaEE, try to download other version.

Type download Eclipse for JavaEE developers in google and try again.

Alexei Petrov
  • 331
  • 5
  • 14