通过jsp调用servlet而不提交表单

时间:2013-09-26 04:55:26

标签: jsp servlets

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

  • 运动                 
                      
                
  • 所以当我点击运动按钮时,我想调用“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); 
    
    
        }
    

    1 个答案:

    答案 0 :(得分:1)

    构建菜单本身时,会将查询字符串附加到该href链接。然后它会将该值发送到您的servlet

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

    然后按如下方式访问servlet中的运动值/任何其他单击的链接值

    String vdo_type = request.getParameter("linkname");