0
WebServlet(name = "category", urlPatterns = {"/category/*"})
public class CategoryController extends HttpServlet {
    private CategoryDAO categoryaDao;

    public void init() {
        CategoryaDao = new CategoryDAO();
    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        doGet(request, response);
    }

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

        try {
            switch (action) {
                case "/category/newCategory":
                    showNewFormCategoria(request, response);
                    break;
                case "/category/showCategory":
                    listCategory(request, response);
                    break;
                case "/category/deleteCategory":
                    deleteCategory(request, response);
                    break;
            }
        } catch (SQLException ex) {
            throw new ServletException(ex);
        }
    }

My issue is that I don't know how to make the path work, already work if I use the urlPattern / but I need to implement more logic to my project so can't use it like that. I tried to pass those actions to /category/* and is not working, how can I pass those actions to category?

Raúl Peñate
  • 342
  • 5
  • 15
  • 1
    Does this help? https://stackoverflow.com/questions/12972914/wildcard-path-for-servlet Btw, since the actions supported by your servlet are finite I'd rather list the urls explicitly: `... urlPatterns = {"/category/newCategory", "/category/showCategory", "/category/deleteCategory"}` (and from a design perspective I'd probably rather go for `/category/create` etc. or yet better for REST). – Thomas Nov 02 '22 at 07:56
  • @Thomas Thanks man I forgot to say it, but it really helped me!! – Raúl Peñate Feb 25 '23 at 11:21

0 Answers0