[英]redirect from one jsp to another jsp
我有個問題。 我必須使用jsp文件(index.jsp和neuesSpiel.jsp)。 當我單擊index.jsp中的按鈕時,我想重定向到neuesSpiel.jsp
這是一些代碼(index.jsp):
按鍵:
<input type="image" src="images/neuesSpiel.png" name="neuesSpiel" height=50% id="neuesSpiel" alt="neuesSpiel">
onclick功能
$("#neuesSpiel").click(function() {
<%response.sendRedirect("neuesSpiel.jsp");%>});
但是,當我打開index.jsp時,我將自動重定向到neuesSpiel.jsp。 我只想在單擊按鈕時進行重定向。 怎么了?
您不能將Java
代碼用作JavaScript的一部分。 以下解決您的問題。
$("#neuesSpiel").click(function() {
window.location.href="neuesSpiel.jsp";
});
您也可以將Java變量傳遞給JavaScript。 例如:
<%
String pageName = "neuesSpiel.jsp";
%>
<input type="button" value="redirect" onclick="redirectPage('<%=pageName%>')" />
您的JavaScript:
function redirectPage(pageName){
window.location.href=pageName;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.