用戶需要提供特定的密碼才能被授權訪問特定頁面。如何從java中的方法發送成功的消息到javascript?
我顯示一個表單,如果用戶輸入正確的密碼將被重定向到一個新的頁面,否則需要顯示一條消息,指出密碼錯誤。我怎樣才能實現它?
目前,我可以使用以下代碼顯示「密碼錯誤」消息,但如果密碼正確,如何重定向用戶。
如果我可以修改xmlhttp對象的返回碼,我可能會滿足要求。
function auth(){
var form = $('#form').serialize();
if(window.XMLHttpRequest)
{
xmlhttp = new XMLHttpRequest();
}
else
{
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if(xmlhttp.readyState == 4 && xmlhttp.status == 200)
{
document.getElementById("background").style.display = "Block";
document.getElementById("box").style.display = "Block";
document.getElementById("results").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("get","../authenticate?"+form,false);
xmlhttp.send();
return false;
}
的Java
public String authenticate()
{
if(user is authenticated)
return a success parameter to JavaScript
else
return a wrong password message to JavaScript
}
信息
後端就是Java。
我知道我可以使用window.location.href來重定向,但需要確保用戶在重定向之前進行身份驗證。
讓我知道什麼是投了反對票? – J888
這是真的* Java問題嗎? –
它與java有關,我想,知道java的人可能會有更好的解決方案。另外有些時候人們也會要求後端語言。 – J888