簡體   English   中英

我們可以將一個jsp頁面重定向到另一個jsp頁面

[英]Can we redirect one jsp page to another jsp page

我想打開一個jsp頁面而不訪問我的servlete代碼。 即我既不必在我的jsp代碼中輸入我的url(action =“url”),也不必訪問我的Servlete代碼。

<form id="main" method="post" name="main" action="dpRegPost" onsubmit="return validate();">

任何人都可以幫助我嗎?

您可以將javascript添加到jsp文件中

<script type="text/javascript">
window.location.href = "www.google.com";
</script>

或使用jsp

<%

    response.sendRedirect("www.google.com");
%>

你也可以試試這個

<jsp:forward page = "abc.jsp" />

在當前的jsp頁面中使用jstl taglibrary。使用下面的代碼提供taglibrary

 <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>  

在jsp中使用以下代碼進行重定向

<c:redirect url="/xxx.jsp"/>

試試這個:

<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();
}

您也可以直接用以下方式調用頁面:

<jsp:redirect page="xyz.jsp" />
use the following code to redirect on another page in js...

$('#abc_id').click(function() {
            updateSubContent("abc.jsp");
        });

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM