试试这个:ServletContext context = getServletContext();
RequestDispatcher dispatcher = context.getRequestDispatcher(path);
dispatcher.forward(req, resp);
RequestDispatcher dispatcher = context.getRequestDispatcher(path);
dispatcher.forward(req, resp);
<%
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文件的相对路径。
问题和你描述的一样,但是,有没有别的 解决方法,不用修改jsp文件呢?难道用servlet转向就一定要在jsp页面中使用绝对路径吗?
RequestDispatcher is used to transfer request Response.sendRedirect() is used to tell Client to find another program in another place
http://localhost:8080/examples而对于sendRedirect,这个"/"则是当前站点的root,同理对应
http://localhost:8080/其他方面两者的异同去看看相关文档吧,到处都有说明。 :)