0

I made my first attempt to create a servlet and in result there is a problem I cannot solve ;(

My entry page, simple hello world, looks this way:

@WebServlet("/")
public class EntryServlet extends HttpServlet {


   @Override
   protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
       resp.setContentType("text/html");

       PrintWriter writer = resp.getWriter();
       writer.println("Hello World");
       writer.close();
   } 

So my expectation to @WebServlet("/") is that GET / returns Hello World page.
All other requests, ex GET /wrong-url should return 404. Surprisingly, after deploying WAR to Wildfly10, I received "Hello World" for each url I tried.

So @WebServlet("/") behaves as kinda @WebServlet("/*") - is it as it should be or am I doing something wrong?

UPDATE
I found the answer here: Difference between / and /* in servlet mapping url pattern

Community
  • 1
  • 1
mrok
  • 2,680
  • 3
  • 27
  • 46

1 Answers1

0

I think use @WebServlet("/helloworld") instead of @WebServlet("/") . so that if you put GET /wrong-url it will give 404 error.

KPJAVA
  • 70
  • 4