log in page

log in page

hi all i want to create a login page in jsp which should be validated using ajax. please help me dong that with code...

View Answers

September 3, 2012 at 5:15 PM

Here is a jsp example that accepts username and password from the user and check whether the user is valid or not by using ajax.

1)ajaxLogin.jsp

<html>
<head>
<script language="javascript">
function postRequest(strURL){
var xmlHttp;
if(window.XMLHttpRequest){ 
var xmlHttp = new XMLHttpRequest();
}
else if(window.ActiveXObject){ 
var xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlHttp.open('POST', strURL, true);
xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xmlHttp.onreadystatechange = function(){
if (xmlHttp.readyState == 4){
updatepage(xmlHttp.responseText);
}
}
xmlHttp.send(strURL);
}

function updatepage(str){
if(str=="yes"){
alert("Welcome User");
}else{
alert("Invalid Login! Please try again!");
}
}

function call_login(){
var username = window.document.f1.username.value;
var password = window.document.f1.password.value;
var url = "login.php?username=" + username + "&password=" +password ;
postRequest(url);
} 
</script>
</head>

<body>
<Center>

<form name="f1" onsubmit="return call_login();">
<table border="0" bgcolor="#CCCCFF" cellspacing="1" cellpadding="3" width="287">
<tr>
<td align="left" colspan="2" width="275"><b><font size="5" color="#000080">Login</font></b></td>
</tr>
<tr>
<td align="right" width="81"><b><font color="#000080">User
Name:</font></b></td>
<td width="184"><input type="text" name="username" id="user" size="20" value="" /></td>
</tr>
<tr>
<td align="right" width="81"><b><font color="#000080">Password:</font></b></td>
<td width="184"><input type="password" name="password" size="20" value="" /></td>
</tr>
<tr>
<td colspan="2" align="center" width="275"><input type="button" name="a1" value="Login" onclick="call_login()"></td>
</tr>
</table>
</form>

</center>
</body>
</html>

2)check.jsp:

<%
String username=request.getParameter("username");
String password=request.getParameter("password");
if(username=="admin" && password=="admin"){
out.println("Valid!");
}else{
out.println("Not Valid!");
}
?>

For more information, visit the following link:

JSP Lgin using Ajax and JQuery


September 4, 2012 at 3:45 PM

hi,thank you... i get invalid user name and password though i give username and password properly..


September 7, 2012 at 5:08 PM

does it pass parameters to the server i.e. check.jsp?









Related Tutorials/Questions & Answers:
log in page
log in page  hi all i want to create a login page in jsp which should be validated using ajax. please help me dong that with code...   Here is a jsp example that accepts username and password from the user and check
keeping log of page load - Java Beginners
keeping log of page load  Hello, I have a project and I need... to keep a log of if the page has succesfuuly loaded or not. It means I want to keep log for sucess and failure both for page loading. Can you please give me some
Advertisements
log in
log in  sir i designed one login.jsp page with one form, username,login,and one submit button .if i enter username and password its been verify the mydatabase in in table in the field of username and password while it s correct
Maven Dependency log >> 1.0
You should include the dependency code given in this page to add Maven Dependency of taglibs >> log version1.0 in your project
Maven Dependency log >> 1.0.1
You should include the dependency code given in this page to add Maven Dependency of co.trikita >> log version1.0.1 in your project
Maven Dependency log >> 1.0.3
You should include the dependency code given in this page to add Maven Dependency of co.trikita >> log version1.0.3 in your project
Maven Dependency log >> 1.1.0
You should include the dependency code given in this page to add Maven Dependency of co.trikita >> log version1.1.0 in your project
Maven Dependency log >> 1.1.4
You should include the dependency code given in this page to add Maven Dependency of co.trikita >> log version1.1.4 in your project
Maven Dependency log >> 1.1.5
You should include the dependency code given in this page to add Maven Dependency of co.trikita >> log version1.1.5 in your project
Maven Dependency Log >> 1.0.0
You should include the dependency code given in this page to add Maven Dependency of com.techshroom >> Log version1.0.0 in your project
Maven Dependency log >> 1.0.2
You should include the dependency code given in this page to add Maven Dependency of co.trikita >> log version1.0.2 in your project
Maven Dependency log >> 1.1.1
You should include the dependency code given in this page to add Maven Dependency of co.trikita >> log version1.1.1 in your project
Maven Dependency commons-jelly-tags-log >> 20040902.071410
You should include the dependency code given in this page to add Maven Dependency of commons-jelly-tags-log >> commons-jelly-tags-log version20040902.071410 in your project
Maven Dependency log-doc >> 1.0
You should include the dependency code given in this page to add Maven Dependency of taglibs >> log-doc version1.0 in your project
Maven Dependency log-examples >> 1.0
You should include the dependency code given in this page to add Maven Dependency of taglibs >> log-examples version1.0 in your project
Maven Dependency e-log >> 3.0.0.RELEASE
You should include the dependency code given in this page to add Maven Dependency of com.17jee >> e-log version3.0.0.RELEASE in your project
Maven Dependency log-utils >> 1.0.0
You should include the dependency code given in this page to add Maven Dependency of com.amlinv >> log-utils version1.0.0 in your project
Maven Dependency globalmentor-log >> 0.5.0
You should include the dependency code given in this page to add Maven Dependency of com.globalmentor >> globalmentor-log version0.5.0 in your project
Maven Dependency log-lib >> 0.1.1
You should include the dependency code given in this page to add Maven Dependency of com.identityblitz >> log-lib version0.1.1 in your project
Maven Dependency log-indexer >> 1.1.0
You should include the dependency code given in this page to add Maven Dependency of com.logicartisan >> log-indexer version1.1.0 in your project
Maven Dependency mailable_log >> 0.1.0
You should include the dependency code given in this page to add Maven Dependency of com.lukekorth >> mailable_log version0.1.0 in your project
Maven Dependency mailable_log >> 0.1.1
You should include the dependency code given in this page to add Maven Dependency of com.lukekorth >> mailable_log version0.1.1 in your project
Maven Dependency mailable_log >> 0.1.2
You should include the dependency code given in this page to add Maven Dependency of com.lukekorth >> mailable_log version0.1.2 in your project
Maven Dependency mailable_log >> 0.1.3
You should include the dependency code given in this page to add Maven Dependency of com.lukekorth >> mailable_log version0.1.3 in your project
Maven Dependency mailable_log >> 0.1.4
You should include the dependency code given in this page to add Maven Dependency of com.lukekorth >> mailable_log version0.1.4 in your project
Maven Dependency mailable_log >> 0.1.5
You should include the dependency code given in this page to add Maven Dependency of com.lukekorth >> mailable_log version0.1.5 in your project
Maven Dependency mailable_log >> 0.1.6
You should include the dependency code given in this page to add Maven Dependency of com.lukekorth >> mailable_log version0.1.6 in your project
Maven Dependency mycila-log >> 1.0
You should include the dependency code given in this page to add Maven Dependency of com.mycila >> mycila-log version1.0 in your project
Maven Dependency mycila-log >> 1.1
You should include the dependency code given in this page to add Maven Dependency of com.mycila >> mycila-log version1.1 in your project
Maven Dependency mycila-log >> 1.2
You should include the dependency code given in this page to add Maven Dependency of com.mycila >> mycila-log version1.2 in your project
Maven Dependency mycila-log >> 1.3
You should include the dependency code given in this page to add Maven Dependency of com.mycila >> mycila-log version1.3 in your project
Maven Dependency mycila-log >> 2.0
You should include the dependency code given in this page to add Maven Dependency of com.mycila >> mycila-log version2.0 in your project
Maven Dependency mycila-log >> 2.1
You should include the dependency code given in this page to add Maven Dependency of com.mycila >> mycila-log version2.1 in your project
Maven Dependency mycila-log >> 2.10
You should include the dependency code given in this page to add Maven Dependency of com.mycila >> mycila-log version2.10 in your project
Maven Dependency mycila-log >> 2.11
You should include the dependency code given in this page to add Maven Dependency of com.mycila >> mycila-log version2.11 in your project
Maven Dependency mycila-log >> 2.12
You should include the dependency code given in this page to add Maven Dependency of com.mycila >> mycila-log version2.12 in your project
Maven Dependency mycila-log >> 2.2
You should include the dependency code given in this page to add Maven Dependency of com.mycila >> mycila-log version2.2 in your project
Maven Dependency mycila-log >> 2.3
You should include the dependency code given in this page to add Maven Dependency of com.mycila >> mycila-log version2.3 in your project
Maven Dependency mycila-log >> 2.4
You should include the dependency code given in this page to add Maven Dependency of com.mycila >> mycila-log version2.4 in your project
Maven Dependency mycila-log >> 2.5
You should include the dependency code given in this page to add Maven Dependency of com.mycila >> mycila-log version2.5 in your project
Maven Dependency mycila-log >> 2.6
You should include the dependency code given in this page to add Maven Dependency of com.mycila >> mycila-log version2.6 in your project
Maven Dependency mycila-log >> 2.7
You should include the dependency code given in this page to add Maven Dependency of com.mycila >> mycila-log version2.7 in your project
Maven Dependency mycila-log >> 2.8
You should include the dependency code given in this page to add Maven Dependency of com.mycila >> mycila-log version2.8 in your project
Maven Dependency mycila-log >> 2.9
You should include the dependency code given in this page to add Maven Dependency of com.mycila >> mycila-log version2.9 in your project
Maven Dependency e-log-service >> 3.0.0
You should include the dependency code given in this page to add Maven Dependency of com.17jee >> e-log-service version3.0.0 in your project
Maven Dependency e-log-service >> 3.0.1.0
You should include the dependency code given in this page to add Maven Dependency of com.17jee >> e-log-service version3.0.1.0 in your project
Maven Dependency e-log-service >> 3.0.1.1
You should include the dependency code given in this page to add Maven Dependency of com.17jee >> e-log-service version3.0.1.1 in your project
Maven Dependency e-log-service >> 3.0.1.3
You should include the dependency code given in this page to add Maven Dependency of com.17jee >> e-log-service version3.0.1.3 in your project
Maven Dependency e-log-service >> 3.0.1.4
You should include the dependency code given in this page to add Maven Dependency of com.17jee >> e-log-service version3.0.1.4 in your project
Maven Dependency e-log-ui >> 3.0.0
You should include the dependency code given in this page to add Maven Dependency of com.17jee >> e-log-ui version3.0.0 in your project

Ads