当用sendRedirect方法切换页面时,URL路径会重定向到你所输入的地址。
即我需要切换到的JSP地址:http://localhost:8080/zpw/View/Home_index.jsp
而我的sendRedirect写法为response.sendRedirect("View/Graduate_index.jsp");用sendRedirect切换页面的问题是,用request.setAttribute等request语句把一些值传给JSP页面
----------------------------------------------------------------------------------------
所以我决定了要用forward来进行页面切换
可用forward切换页面的话,貌似URL路径不会重定向,
而还是Servlet的路径:http://localhost:8080/zpw/Servlet
路径不会重定向的结果是,转到JSP页面后,我JSP页面原本的图片没了,超链接也没了(估计是因为路径没切换到JSP页面的路径,所以图片和超链接的地址都不对了),只剩下表格和文字还在(一些与路径无关的东西)。如何解决我用forward时,图片和超链接没了这个问题???

解决方案 »

  1.   

    附上部分代码,不知道是不是我的代码有问题
    Servlet:
    //response.sendRedirect("View/Home_index.jsp");
    disp = request.getRequestDispatcher("/View/Home_index.jsp");
    disp.include(request, response);所要切换的JSP页面:
    <jsp:include page="Top.jsp" flush="true"/>
        <jsp:include page="Home_navigation.jsp" flush="true"/>
        <table width="778" border="1" align="center" cellpadding="0" cellspacing="0">
      <tr>
        <td width="190" height="600"><jsp:include page="Home_left.jsp" flush="true"/></td>
        <td><jsp:include page="Right.jsp" flush="true"/></td>
      </tr>
    </table>
    <jsp:include page="Bottom.jsp" flush="true"/>其中一个JSP页面里面的图片地址连接:
    <td height="134" valign="top" background="../Images/login_bottom.jpg">
      

  2.   

    楼主又新发了个帖子啊,我在你另一个帖子解释了:forward的问题在于:所有后续资源请求将仍然以Servlet的URL为基础,所以你的原来以JSP页面为基础的相对路径必然是什么东西都找不到的,除非你的相对路径是以Servlet的位置为基础的相对路径。所以各项资源的引用,建议你要用绝对路径。另:因为绝对路径有一个很有意思的问题就是“ContextRoot”,所以你会看到绝大多数JSP页面都会有:request.getContextPath();