enter image description here Hello everyone, I made a servlet for tomcat, I go to the site and he gives me a mistake:

HTTP Status 500 - index (wrong name: web / index)

type Exception report

message index (wrong name: web / index)

Description The server encountered an internal error that prevented it from fulfilling this request.

exception

java.lang.NoClassDefFoundError: index (wrong name: web / index)

what to do ?

Here is the servlet code:

package web; import java.io.IOException; import java.io.PrintWriter; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; public class Index extends HttpServlet { @Override public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { res.setContentType("text/html"); PrintWriter out = res.getWriter(); out.println("<html>"); out.println("<head>"); out.println("<title>asd</title"); out.println("</head>"); out.println("</html>"); } } 

web.xml:

  <web-app xmlns="http://java.sun.com/xml/ns/javaee" version="2.5"> <servlet> <servlet-name>index</servlet-name> <servlet-class>web/Index</servlet-class> </servlet> <servlet-mapping> <servlet-name>index</servlet-name> <url-pattern>/index</url-pattern> </servlet-mapping> </web-app> 

enter image description here

  • <servlet-class>web.index</servlet-class> - Sergey Gornostaev
  • @ SergeyGornostaev, thanks for the quick reply, I now have a bug HTTP Status 500 error - Error instantiating servlet class web.index - as1andrey1
  • web.Index and not web/Index - Sergey Gornostaev
  • @ Sergei Gornostaev is not what has changed, the error is the same - as1andrey1

1 answer 1

You declare everything simultaneously both in annotations and in web.xml. You have to use one thing.

In index you need to specify the full name of the class. You have this, apparently, web.index

And the class names are written with a capital letter.

  • I changed the name of the class and added the web <servlet-class> web.Index </ servlet-class>. I have removed from my @Override code now another error javax.servlet.ServletException: Error instantiating servlet class web.Index - as1andrey1
  • Leave @Override and remove @WebServlet ("/ s"); - mipan
  • java.lang.ClassNotFoundException error: web / Index javax.servlet.ServletException: Error instantiating servlet class web / Index - as1andrey1
  • Update the question: write the actual servlet code, web.xml, add the complete output of the template and the structure of your project. - mipan
  • updated and wrote everything - as1andrey1