1

I have a servlet, is possible to call every method in 1 servlet to manage list data on the JSP page?

For example i can call in JSP <a href="/SortServlet">click me</a> and it will sort by condition in doGet, but it makes only for 1 link, is possible to call all methods by different links from JSP in only 1 servlet, by assigning each link to each method, or I should do 1servlet - 1method(in doGet) to manage data and assign each link to their servlets?

/SortServlet
protected void doGet(javax.servlet.http.HttpServletRequest request,
                          javax.servlet.http.HttpServletResponse response)
            throws ServletException, IOException {
        List<Course> listCourse = CourseDAO.getCourses();
        request.setAttribute("list_course", listCourse);
        RequestDispatcher dispatcher = request.getRequestDispatcher("index.jsp");
        dispatcher.forward(request, response);

    }

    public List <Course> getByName(String name, List <Course> courseList){
        // some logic
        return courseList;
    }

    public List <Course> sortByQuantiny(List <Course> courseList){
        // some logic
        return courseList;
    }
    
    public List <Course> sortByAz(List <Course> courseList){
        //Collections.sort(courseList);
        return courseList;
    }

For example 1 link call /SortServlet method getByName

2 link call /SortServlet method sortByQuantiny

3 link call /SortServlet method sortByAz

<div>
            <a href="/SortServlet">getByName</a>
            <a href="#">sortByQuantiny</a>
            <a href="#">sortByAz</a>
</div>

right now, i understand only how to call getByname because i can call it in doGet

I hope I explained clearly

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Max
  • 253
  • 2
  • 16

0 Answers0