0

This is web.xml

<servlet>
    <servlet-name>ClientServlet</servlet-name>
    <servlet-class>ma.fstt.web.ClientServlet</servlet-class>
</servlet>
 
<servlet-mapping>
    <servlet-name>ClientServlet</servlet-name>
    <url-pattern>/client</url-pattern>
</servlet-mapping>

And this is the ClientServlet.java

package ma.fstt.web;

public class ClientServlet extends HttpServlet {
    ...
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        String action = request.getServletPath();

        try {
            switch (action) {
                case "/new":
                    showNewForm(request, response);
                    break;
                                ...
                default:
                    listClients(request, response);
                    break;
            }
        } catch (SQLException ex) {
            throw new ServletException(ex);
        }
    }
        ...
}

I'm trying to access the showNewForm by http://localhost:8081/Atelier1/client/new and this error show up enter image description here

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555

2 Answers2

0

Try @WebServlet("/client") instead of url-pattern in web

0

I resolved this problem by adding a variable in the path

package ma.fstt.web;

public class ClientServlet extends HttpServlet {
    ...
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        String action = request.getParameter("action");

        try {
            switch (action) {
                case "/new":
                    showNewForm(request, response);
                    break;
                                ...
                default:
                    listClients(request, response);
                    break;
            }
        } catch (SQLException ex) {
            throw new ServletException(ex);
        }
    }
        ...
}