Reputation: 3776
document.location()
function given in the logn.js
code works fine in Internet Explorer but does not work in Firefox. The given js code is for implementing AJAX in the login page .. AJAX directs the code to a servlet which if login OK gives user Login as response.
logn.js
function logn(emailId,password) {
var parameters="emailId="+emailId+"&password="+password;
var xmlhttp;
if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
} else { // code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
if(xmlhttp.responseText.toString()=="User Login") {
document.location("userhome.jsp");
} else if(xmlhttp.responseText.toString()=="Admin Login") {
document.location("adminhome.jsp");
}else {
//document.getElementById("message").innerHTML = xmlhttp.responseText;
alert(xmlhttp.responseText);
}
}
};
xmlhttp.open("POST", "LoginServlet", true);
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlhttp.send(parameters);
}
the following is the servlet code LoginServlet.java
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
PrintWriter out=response.getWriter();
String emailId=request.getParameter("emailId");
String password=request.getParameter("password");
if (emailId.isEmpty()||password.isEmpty()) {
out.write("Please enter EmailId/Password");
} else {
LoginModel lm=new LoginModel();
lm.setEmailId(emailId);
lm.setPassword(password);
LoginService ls=new LoginService();
lm=(LoginModel) ls.loginCheck(lm);
if(lm!=null){
System.out.println("login ok");
HttpSession session =request.getSession();
System.out.println(lm.getLoginId());
session.setAttribute("userlogin", lm);
if (lm.getIsAdmin()==0) {
System.out.println("aaaaaaaaaaa");
out.write("User Login");
}
else if (lm.getIsAdmin()==1)
out.write("Admin Login");
ls.setIsActive(lm.getLoginId(),1);
} else
out.write("Wrong EmailId/Password");
}
}
Upvotes: 0
Views: 1750
Reputation: 707526
You should be using:
window.location = "userhome.jsp";
and
window.location = "adminhome.jsp";
There were a couple issues with how you were doing it. It's preferred to use window.location
instead of document.location
. And, you assign to it, not call it like a function.
MDN reference: https://developer.mozilla.org/en/DOM/window.location
Upvotes: 2