0

我们知道我们可以通过将其放在标签下方来重定向网站:

<head>
  <meta content=0;url=http://www.google.com http-equiv='Refresh'/>
</head>

但是,如果我想要重定向的链接不是google.com,但它存储在我从 Java 代码处理的字符串变量中,会发生什么?我知道如果它从头向下加载,那么它会立即重定向到该页面,而无需通过以下代码,对吗?那么,如何组合我提取的字符串并让网站加载到该链接?

4

2 回答 2

0

从 JSP(或 servlet):

<%
    response.sendRedirect(redirectURL);
%>

其中 redirectURL 是包含您要访问的页面的变量。

于 2013-05-31T17:48:50.057 回答
0

好的,最后我想通了:首先,需要在 web 应用程序中构造 index.jsp 及其 java 类: https ://netbeans.org/kb/docs/web/quickstart-webapps.html 然后在索引中。 jsp,使用它从该 java 类中获取变量并重定向:

<%@page import = "org.mypackage.Webredirect.*" %>
<%Webredirect obj = new Webredirect();%>
 <%response.sendRedirect( obj.getName());%>

谢谢你。

于 2013-06-02T09:07:26.897 回答