Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


vanchinathan R
log in page
3 Answer(s)      2 years and 2 months ago
Posted in : JSP-Servlet


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


Advertisement
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
Log-in Valdidation
Log-in Valdidation  how to create login validation in jsp
log out
log out  how do i create a log out on a project without it exiting system so it does not reload again
user log in according to their role
user log in according to their role  i want a jsp code for different users log in to different pages according to their role.example normal user and administrator. normal user for user page and administrator for admin page
user log in according to their role
user log in according to their role  i want a jsp code for different users log in to different pages according to their role.example normal user and administrator. normal user for user page and administrator for admin page
log 4j
log 4j  what is log4j? can you give me clear information about log4j?   Please go through the following link: log4j Tutorials
failure to log in
failure to log in  <blockquote> <p>Blockquote</p> </blockquote> <p>&lt;%@page contentType="text/html"%> &lt;%@page pageEncoding="UTF-8"%> &lt;%@page import
error log
error log  hi my requirement is validate xml and xsd in java.If there is an errors then i will log error and store into error table. so plz if any one knows send code urgent. error table details-------------- Table
Writing Log Records to a Log File
Writing Log Records to a Log File       This section demonstrates for writing log records to a log file. Logger provides different types of level like: warning, info
error log and send Database
error log and send Database  hi my requirement is validate xml and xsd in java.If there is an errors then i will log error and store into error table. so plz if any one knows send code urgent. error table details
Error in log file
Error in log file  Hi, I AM using Apache tomcat 6.0.16 server... of executing project i get following errors in "Apache Tomcat 6.0.16 log". Apr 17, 2011 11:57:57 AM org.apache.catalina.core.ApplicationContext log INFO: Marking
Error in log file
Error in log file  Hi, I AM using Apache tomcat 6.0.16 server... of executing project i get following errors in "Apache Tomcat 6.0.16 log". Apr 17, 2011 11:57:57 AM org.apache.catalina.core.ApplicationContext log INFO: Marking
Error in log file
Error in log file  Hi, I AM using Apache tomcat 6.0.16 server... of executing project i get following errors in "Apache Tomcat 6.0.16 log". Apr 17, 2011 11:57:57 AM org.apache.catalina.core.ApplicationContext log INFO: Marking
Context Log Example Using Servlet
to server log file when servlet is called. In the following JSP page (message.jsp) we... parameter of jsp page in "message" variable and set this message to the log... Context Log Example Using Servlet  
Using Log Files
Using Log Files          Log files keeps a records of internet protocol addresses.... In this program we are writing some information in log file.   The code
JSP cannot log to FileAppender - Log4J
JSP cannot log to FileAppender  Hi, Thank you for your attention... method. But when the LogClass is called from jsp file, no log file is created... ----------------------------------------------------------------------------- ### direct log messages to stdout
Dealing with negative lat/log numbers
Dealing with negative lat/log numbers  I need to run a script that will return cities that match within a certain range of the latitude and longitude. We are trying to check to make sure what we return for lat/log matches close
Creating a log in a text file - Applet
Creating a log in a text file  Hey there, I have created an applet that supports 4 different languages, and the applet needs to be runnable... that keeps a log of the time of when the application is run and closed, every
Log In Form Validations - Java Beginners
Log In Form Validations  Good Morning Sir ,I have Created Log in Form with Databse Connectivity and i have took two JTextFields 1)USERNAME 2)password if two Jtextfields are blanks i want to show msg blank Username
Where is servlet log file in net beans?
Where is servlet log file in net beans?  When you use context.log("some string"); then the string get written into the servlet log file. But where is the servlet log file in netbeans? I am using netbeans 6.9. I can't locate
Redirect the log used by DriverManager and JDBC driver
Redirect the log used by DriverManager and JDBC driver  How can I get or redirect the log used by DriverManager and JDBC drivers
Write to the log used by DriverManager and JDBC drivers.
Write to the log used by DriverManager and JDBC drivers.  How can I write to the log used by DriverManager and JDBC drivers
Use Log in Servlet Context
Use Log in Servlet Context       This section illustrates you how to use log in Servlet Context. We.... The method context.log() writes the specified message to a servlet log file
Log out from website - JSP-Servlet
Log out from website  what is the code to how to log out from......LoginPage.jsp<html><head><title>login page in jsp</title>...;loginAction.jsp"> <h2>Login Page In JSP</h2> <table border
Limiting the Size of a Log File in Java
Limiting the Size of a Log File in Java  ... to limit the size of a log file in Java. Log files haven't any boundation at the file creation time but Java provides the facility for limiting the size of a log
Java error log
Java error log       Java error log is a error that arises due to internal error. A error logger is simple an object that is used to show an error log message
Getting the Log Level of a Logger
Getting the Log Level of a Logger       This section helps you to learn about the getting log level... with the log level and the log message for the specific log record. And the last
Forward Log Records to Its Parent
Forward Log Records to Its Parent       This section describes how to forward log records to its parent. You know that a logger sends both log records (messages declared
Writing Log Records Only After a Condition Occurs
Writing Log Records Only After a Condition Occurs       This section deals with log records those have been written in a log file if  the "if" conditions
 

 

 

DMCA.com