0

在我的应用程序中有这样的菜单栏,

  • 运动的
  • 所以当我点击运动按钮时,我想调用“getlink”servlet 并提交值“sport”。我尝试了几种方法,但没有一个是正确的。

    这是我的 servlet

     protected void doGet(HttpServletRequest request, HttpServletResponse response)
                throws ServletException, IOException {
    
            String vdo_type = request.getParameter("Science");
    
                  int page = 1;
            int recordsPerPage = 10;
            if(request.getParameter("page") != null)
                page = Integer.parseInt(request.getParameter("page"));
          //  EmployeeDAO dao = new EmployeeDAO();
            Getlink_Dao be=new Getlink_Dao();
            List<Utube_to> list = be.getRecentAdd((page-1)*recordsPerPage,
                                     recordsPerPage,vdo_type);
            int noOfRecords = be.getNoOfRecords();
            int noOfPages = (int) Math.ceil(noOfRecords * 1.0 / recordsPerPage);
            request.setAttribute("allvdos", list);
            request.setAttribute("noOfPages", noOfPages);
            request.setAttribute("currentPage", page);
            RequestDispatcher view = request.getRequestDispatcher("Home.jsp");
            view.forward(request, response); 
    
    
        }
    
    4

    1 回答 1

    1

    While building the menu itself append query string to that href link like this. Then it will send that value to your servlet

    <li><a href="getlink?linkname=sport"></a></li>
    

    then access that sport value/any other clicked link value in your servlet as follows

    String vdo_type = request.getParameter("linkname");
    
    于 2013-09-26T05:44:23.687 回答