2014-11-08 32 views
1

我有以下JSP:如何在JSP中做html重定向?

<% 
    String Target_Url=request.getSession().getAttribute("Target_Url").toString(); 
    Target_Url="http://www.yahoo.com"; 
%> 

<html xmlns="http://www.w3.org/1999/xhtml"> 
    <head> 
     <script type="text/javascript"> 
     if (window.top.location != window.location) 
     { 
      window.top.location.href=window.location.href; 
     } 
     </script> 
     <META http-equiv="refresh" content="0;URL=${Target_Url}"> 

    </head> 
    ... 
</html> 

這是一個框架內,並應重定向到頂層的位置,但它沒有這樣做,它使重定向到它的自我,但如果像我硬編碼下面,它的工作原理:

<META http-equiv="refresh" content="0;URL=http://www.yahoo.com"> 

我猜:content="0;URL=${Target_Url}"不正確,什麼是正確的格式?

+0

決不做HTML重定向。如果你想做一個重定向,在HTTP中執行。 – Quentin 2014-11-09 08:36:10

回答

1

正確的格式:

<META http-equiv="refresh" content="0;URL=<%=Target_Url%>">