javaweb转发forward报错

工具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个回答

你这个软件有问题的,你要重新安装就好了,

hu18315778112
hoO丶 把那个servlet类删除重写就好了!!!服了
大约一年之前 回复

看一下依赖的jar包版本对不对 或者是IDE的问题了

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问