试试这个:ServletContext context = getServletContext();
RequestDispatcher dispatcher = context.getRequestDispatcher(path);
dispatcher.forward(req, resp);

解决方案 »

  1.   

    你一定是在news/index.jsp文件中的图像引用时使的是相对路径,要改成绝对路径。
    <%
         String path = request.getContextPath();
         path = path + "/news/images/xx.bmp";
    %>
         <img src= <%=path%>>在Servlet中调用request.getRequestDispatcher(paht).forward(req,resp);方法,你看网址还是
    那个Servlet的网址,而不是那个JSP文件的网址,所以在JSP文件中的图像的相对路径是相对于Servlet的,而不是JSP文件的相对路径。
      

  2.   

    多谢aurain(aurain) 
    问题和你描述的一样,但是,有没有别的 解决方法,不用修改jsp文件呢?难道用servlet转向就一定要在jsp页面中使用绝对路径吗?
      

  3.   

    这就不知道了!我也是刚学Servlet不久,你还是问高手吧,不过我觉得不行!
      

  4.   


    RequestDispatcher is used to transfer request Response.sendRedirect() is used to tell Client to find another program in another place
      

  5.   

    没有细看,不过对于getRequestDispatcher来说,无论是include/forward,"/"意味着当前webapp的根。也就是说,如果在examples这个webapp下,"/"就是对应:
    http://localhost:8080/examples而对于sendRedirect,这个"/"则是当前站点的root,同理对应
    http://localhost:8080/其他方面两者的异同去看看相关文档吧,到处都有说明。 :)