Java 我们可以将一个jsp页面重定向到另一个jsp页面吗
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23517921/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Can we redirect one jsp page to another jsp page
提问by Brain
I want to open a jsp page without accessing my servlete code. i.e. I neither have to input my url in (action="url") my jsp code nor have to access my Servlete code.
我想在不访问我的 servlete 代码的情况下打开一个 jsp 页面。即我既不必在 (action="url") 我的 jsp 代码中输入我的 url,也不必访问我的 Servlete 代码。
<form id="main" method="post" name="main" action="dpRegPost" onsubmit="return validate();">
Can anyone help me in this?
任何人都可以帮助我吗?
采纳答案by Susheel Singh
Try this:
尝试这个:
<form id="main" method="post" name="main" action="" onsubmit="redirect(this);">
<input type="submit" name="submit"/>
</form>
function redirect(elem){
elem.setAttribute("action","somepage.jsp");
elem.submit();
}
回答by Naveen
Use jstl taglibrary in your current jsp page.Make available the taglibrary using below code
在您当前的 jsp 页面中使用 jstl taglibrary。使用以下代码使 taglibrary 可用
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
Use Following code in jsp to redirect
在jsp中使用以下代码重定向
<c:redirect url="/xxx.jsp"/>
回答by Mustafa sabir
You can add javascript to your jsp file
您可以将 javascript 添加到您的 jsp 文件中
<script type="text/javascript">
window.location.href = "www.google.com";
</script>
or using jsp
或者使用jsp
<%
response.sendRedirect("www.google.com");
%>
回答by Pramod S. Nikam
You can also call page directly with:
您也可以直接调用页面:
<jsp:redirect page="xyz.jsp" />
回答by Nerys
You can also try this
你也可以试试这个
<jsp:forward page = "abc.jsp" />
回答by Prashant
use the following code to redirect on another page in js...
$('#abc_id').click(function() {
updateSubContent("abc.jsp");
});