简体   繁体   中英

maven servlet HTTP Status 404 -

Cant run maven servlet whatever i do. If i restart server, ill get next error:

     HTTP Status 500 - Error instantiating servlet ---

If i restart page without restarting a server - ill get

     HTTP Status 404 - 

There is maven project structure.

在此处输入图片说明 web.xml:

     <!DOCTYPE web-app PUBLIC
 "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
 "http://java.sun.com/dtd/web-app_2_3.dtd" >

     <web-app>
       <display-name>Archetype Created Web Application</display-name>
       <servlet>
          <servlet-name>Cezar</servlet-name>
          <display-name>Cezar</display-name>
          <description></description>
          <servlet-class>Cezar</servlet-class>
       </servlet>
       <servlet-mapping>
          <servlet-name>Cezar</servlet-name>
          <url-pattern>/Cezar</url-pattern>
       </servlet-mapping>
     </web-app>

Cezar.java:

      import java.io.IOException;
      import javax.servlet.ServletException;
      import javax.servlet.http.HttpServlet;
      import javax.servlet.http.HttpServletRequest;
      import javax.servlet.http.HttpServletResponse;

      public class Cezar extends HttpServlet {
          public void doGet(HttpServletRequest request, HttpServletResponse                   response)
        throws IOException{
            PrintWriter out = response.getWriter();
            out.println("<html>");
            out.println("<body>");
            out.println("<h1>Hello Servlet Get</h1>");
            out.println("</body>");
            out.println("</html>"); 
        }
   }

deployment assembly:

在此处输入图片说明

Your application has a structural error.

The source file Cezar.java should be in src/main/java instead of src/main/resources .

Therefore the file is not being compiled into the Cezar.class file which would be added to your web application's WEB-INF/classes directory.

是的,他是真实的,最好维护软件包的结构,并在示例中的web.xml中给出完全限定的名称:您的软件包名称。您的servlet类名称。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM