2011-01-21 56 views
1

在我們有多少方式可以重定向到下一個JSP頁面從一個頁面到另一個頁面除了以下兩種方式,有多少種方式在jsp中重定向到下一頁?

RequestDispatcher rd = request.getRequestDispatcher("MyPage.jsp"); 
rd.forward(request, response); 

response.sendRedirect("MyPage.jsp"); 

,當我去到第二頁(MyPage.jsp )它必須從服務器端加載的新的一頁,從JGuru

回答

2

RequestDispatcher和sendRedirect是different things。如果你想

負載從服務器端的新的一頁,

那麼的RequestDispatcher將無法正常工作。客戶端(瀏覽器)仍然認爲內容來自原始請求。

0

採取:

http://www.jguru.com/faq/view.jsp?EID=376&page=2

You can also physically alter the Location HTTP header attribute, as shown below: 

<% 
response.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY); 
String newLocn = "/newpath/index.html"; 
response.setHeader("Location",newLocn); 
%> 
+0

物理上? :-) – aioobe 2011-01-21 15:57:34

0

重定向有兩種類型的永久和臨時重定向。