Почему я не могу правильно перенаправить свой сервлет Java?

это, наверное, глупый вопрос, но я действительно застрял и нуждаюсь в вашей помощи. Я сделал сервлет Java, который обрабатывает запросы демонстрационного приложения CRUD. Это мой сервлет:

public class AuthorController extends HttpServlet {
    private static final long serialVersionUID = 1L;
    private AuthorDAO authorDAO;

    public void init() {
        String jdbcURL      = getServletContext().getInitParameter("jdbcURL");
        String jdbcUsername = getServletContext().getInitParameter("jdbcUsername");
        String jdbcPassword = getServletContext().getInitParameter("jdbcPassword");

        authorDAO = new AuthorDAO(jdbcURL, jdbcUsername, jdbcPassword);

    }

    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();
        System.out.println(action);
        try {
            switch (action) {
            case "/newAuthor":
                showNewForm(request, response);
                break;
            case "/insertAuthor":
                insertAuthor(request, response);
                break;
            case "/deleteAuthor":
                deleteAuthor(request, response);
                break;
            case "/editAuthor":
                showEditForm(request, response);
                break;
            case "/updateAuthor":
                updateAuthor(request, response);
                break;
            default:
                listAuthor(request, response);
                break;
            }
        } catch (SQLException ex) {
            throw new ServletException(ex);
        }
    }

    
    /* List all authors */
    private void listAuthor(HttpServletRequest request, HttpServletResponse response)
            throws SQLException, IOException, ServletException {
        List<Author> listAuthor = authorDAO.listAllAuthors();
        request.setAttribute("listAuthors", listAuthor);
        RequestDispatcher dispatcher = request.getRequestDispatcher("AuthorList.jsp");
                
        dispatcher.forward(request, response);
    }
    
    
    /* Show authors form */
    private void showNewForm(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        RequestDispatcher dispatcher = request.getRequestDispatcher("AuthorForm.jsp");
        
        dispatcher.forward(request, response);
    }
    
    
    /* Show authors edit form */
    private void showEditForm(HttpServletRequest request, HttpServletResponse response)
            throws SQLException, ServletException, IOException {
        int id               = Integer.parseInt(request.getParameter("id"));
        Author existingAuthor        = authorDAO.getAuthor(id);
        RequestDispatcher dispatcher = request.getRequestDispatcher("AuthorForm.jsp");
        
        request.setAttribute("author", existingAuthor);
        
        dispatcher.forward(request, response);
    }
    

    /* Inserting a new author */
    private void insertAuthor(HttpServletRequest request, HttpServletResponse response) 
            throws SQLException, IOException {
        String author_name    = request.getParameter("author_name");
        int author_age        = Integer.parseInt(request.getParameter("author_age"));
        String author_country = request.getParameter("author_country");

        Author newAuthor = new Author(author_name, author_age, author_country);
        authorDAO.insertAuthor(newAuthor);
        
        response.sendRedirect("listAuthor");
    }

    
    /* Updating an existing author */
    private void updateAuthor(HttpServletRequest request, HttpServletResponse response) 
            throws SQLException, IOException {
        int id        = Integer.parseInt(request.getParameter("id"));
        String author_name    = request.getParameter("author_name");
        int author_age        = Integer.parseInt(request.getParameter("author_age"));
        String author_country = request.getParameter("author_country");

        Author author = new Author(id, author_name, author_age, author_country);
        authorDAO.updateAuthor(author);
        
        response.sendRedirect("listAuthor");
    }

    
    /* Deleting an existing author */
    private void deleteAuthor(HttpServletRequest request, HttpServletResponse response) 
            throws SQLException, IOException {
        int id = Integer.parseInt(request.getParameter("id"));

        Author author = new Author(id);
        authorDAO.deleteAuthor(author);
        
        response.sendRedirect("listAuthor");
    }
}

А это мой файл web.xml:

<servlet>
    <servlet-name>AuthorController</servlet-name>
    <servlet-class>org.demo.AuthorController</servlet-class>
</servlet>
<servlet-mapping>
    <servlet-name>AuthorController</servlet-name>
    <url-pattern>/listAuthor</url-pattern>
</servlet-mapping>

Однако, когда я пытаюсь получить доступ к http: // localhost: 8080 / listAuthor / newAuthor, Почтальон выдает мне ошибку 404. Что я делаю неправильно? Я совершенно запутался в этом отображении и не могу заставить его работать. Я могу получить доступ к: http: // localhost: 8080 / listAuthor и перечислить свою таблицу с авторами, но не могу добавить новую.


person NewJavaEnthusiast    schedule 22.11.2020    source источник
comment
Как вы думаете, что <url-pattern>/listAuthor</url-pattern> делает в <servlet-mapping>?   -  person Sotirios Delimanolis    schedule 22.11.2020
comment
@SotiriosDelimanolis хорошо отображает мой сервлет на этот именованный URL-адрес, я думаю   -  person NewJavaEnthusiast    schedule 22.11.2020
comment
Так есть ли еще что-нибудь, связанное с другими URL-адресами?   -  person Sotirios Delimanolis    schedule 22.11.2020
comment
stackoverflow .com / questions / 15385596 /.   -  person Sotirios Delimanolis    schedule 22.11.2020
comment
можно ли получить доступ к http://localhost:8080/AuthorList.jsp из браузера?   -  person Jude Niroshan    schedule 22.11.2020
comment
@JudeNiroshan да, я могу получить доступ к jsp вот так.   -  person NewJavaEnthusiast    schedule 22.11.2020
comment
@SotiriosDelimanolis Я читаю эту статью и пробовал использовать ‹url-pattern› listAuthor / * ‹/url-pattern›, но это все еще не работает. Я чувствую себя глупо, но не могу найти решения   -  person NewJavaEnthusiast    schedule 22.11.2020
comment
@SKumar да, да, я могу получить доступ как к AuthorList.jsp, так и к AuthorForm.jsp таким образом   -  person NewJavaEnthusiast    schedule 22.11.2020