javaxmleclipsetomcatsts

Mapping error (I guess) while running a servlet on STS(eclipse) through Tomcat


I've just installed "Spring Tool Suite 4" and "Apache Tomcat 10" to learn about Web Application. Following some instructions, I created a new Dynamic Web Project(named 'hello') and a new servlet(named 'HelloServlet').

HelloServlet goes like

package practice;
/**
 * Servlet implementation class HelloServlet
 */

public class HelloServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public HelloServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

    /**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        out.print("<h1>Hello Servlet</h1>");
    }

}

When HelloServlet is run on server, it is directed to "http://localhost:8080/hello/WEB-INF/classes/practice/HelloServlet.java", not "http://localhost:8080/hello/HelloServlet" and 404 error is returned.

I found out '@WebServlet' is not automatically added when creating new servlet unlike instructoin I followed. I added @WebServlet("/HelloServlet") and then Tomcat Server returned error while starting the server.

Some additional STS and Tomcat configurations are needed?


Solution

  • This is bug 577703, which is fixed in the upcoming March release.