Two things here.
If you want your servlet to serve the root URL, you have to do two things
1 - you have to set your webapp context to root, like this
2 - then you have to set your servlet context to root too
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@WebServlet("/")
public class MyServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
public MyServlet() {
super();
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.getWriter().write("OK");
response.getWriter().flush();
}
}
that's because the URL your servlet serve is like this
http://yourserver:port/yourapp/yourservlet
where yourapp is defined by #1
and yourservlet is defined by #2
like this