Problem in servlet url-pattern JAVA

ahmedep Posts 9 Registration date Saturday November 27, 2021 Status Member Last seen November 19, 2022 - Updated on Nov 19, 2022 at 08:51 AM
gorgeousgorilla Posts 1 Registration date Friday November 25, 2022 Status Member Last seen November 25, 2022 - Nov 25, 2022 at 02:54 AM

This is the web.xml file :

<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 a part of ClientServlet.java file :

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 want to call the "showNewForm()" method with the url : "http://localhost:8081/Atelier1/listarticleclient/new"

When i did i got this error :

1 reply

gorgeousgorilla Posts 1 Registration date Friday November 25, 2022 Status Member Last seen November 25, 2022
Updated on Nov 25, 2022 at 04:16 AM

Hi,

There seem to be least three issues

Classes are searched in WEB-INF/classes rather than in WEB-INF

Use the HttpServlet instead of the generic Servlet

Overwrite the doXXX methods of the HttpServlet and not the generic service method. The service method dispatches to the corresponding doXXX method.

0