2014-11-08 49 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%>">