hu18315778112
hoO丶
2018-11-24 01:15

javaweb转发forward报错

  • 请求转发forward
  • 过滤器filter
  • eclipse

工具eclipse——本意是通过filter过滤,如下:

 public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
            throws IOException, ServletException {
        HttpServletRequest req = (HttpServletRequest) request;
        if (req.getSession().getAttribute("hotproductlist") != null) {
            chain.doFilter(req, response);
        } else {
            req.getRequestDispatcher(req.getContextPath() + "/findHotProduct").forward(req, response);
        }
    }

这里一切正常,但是servlet的forward报错:

 public void doGet(HttpServletRequest request, HttpServletRequest response) throws ServletException, IOException {
        ProductService service=new ProductService();
        List<Product> hotproductlist=new ArrayList<Product>();
        hotproductlist=service.findHotProduct();
        request.getSession().setAttribute("hotproductlist", hotproductlist);
        request.getRequestDispatcher(request.getContextPath()+"/index.jsp").forward(request, response);;
    }

这里的forward报错The method forward(ServletRequest, ServletResponse) in the type RequestDispatcher is not applicable for the arguments (HttpServletRequest, HttpServletRequest)
我觉得是编译器的原因,但是怎么都弄不好,求大佬们指点!!!

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

2条回答