Following Example Illustrates the Login Functionality Implemented in simplest form using Phonegap.
Following is the Algo/Logic used in the Sample Application,
- From the Phonegap app, User Enters User Name & Password,
- From the app, JQuery-Ajax Request is made to the Servlet, Sending username & password as parameters,
- Servlet Accepts the Parameters, Then Connects to Remote Database using JDBC and fetches Username and Passwords,
- Matches the username and password from parameters and those fetched from database,
- If credentials matches writes Response as "SUCCESS" else "FAIL"
- At the Client side i.e. Phonegap App, Appropriate Alert message is shown depending on the Response Got from Servlet.
Following is the Server Side - Servlet Snippet Code,
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
Connection con = null;
ResultSet resultSet = null;
String param_uname = request.getParameter("uname");
String param_pwd = request.getParameter("pwd");
try {
Class.forName("<DB Driver>").newInstance();
String url = "<DB URL>";
con = DriverManager.getConnection(url);
String query = null;
query = "SELECT * from APP.LOGIN";
PreparedStatement statement = con.prepareStatement(query);
resultSet = statement.executeQuery();
String db_uname="";
String db_pwd="";
while (resultSet.next()) {
db_uname = resultSet.getString("UNAME");
db_pwd = resultSet.getString("PWD");
}
if( (param_uname.equals(db_uname)) && (param_pwd.equals(db_pwd))){
out.write("SUCCESS");
} else {
out.write("FAIL");
}
} catch (Exception e) {
e.printStackTrace();
} finally {
out.close();
}
PrintWriter out = response.getWriter();
Connection con = null;
ResultSet resultSet = null;
String param_uname = request.getParameter("uname");
String param_pwd = request.getParameter("pwd");
try {
Class.forName("<DB Driver>").newInstance();
String url = "<DB URL>";
con = DriverManager.getConnection(url);
String query = null;
query = "SELECT * from APP.LOGIN";
PreparedStatement statement = con.prepareStatement(query);
resultSet = statement.executeQuery();
String db_uname="";
String db_pwd="";
while (resultSet.next()) {
db_uname = resultSet.getString("UNAME");
db_pwd = resultSet.getString("PWD");
}
if( (param_uname.equals(db_uname)) && (param_pwd.equals(db_pwd))){
out.write("SUCCESS");
} else {
out.write("FAIL");
}
} catch (Exception e) {
e.printStackTrace();
} finally {
out.close();
}
Following is the Snippet Of The HTML Code for PhoneGap Application,
<div data-role="content" id="input_login">
<ul data-role="listview" data-divider-theme="b" data-inset="true">
<li data-role="list-divider" role="heading">
User Name
</li>
<li data-role="list-divider" >
<input type="text" id="txt_username"/>
</li>
<li data-role="list-divider" role="heading">
Password
</li>
<li data-role="list-divider" >
<input type="password" id="txt_pwd"/>
</li>
<li data-role="list-divider" >
<input type="button" id="btn_login" value="Login" onclick="javascript:verifyLogin();"/>
</li>
</ul>
</div>
Following is the JavaScript Function / Code,
function verifyLogin(){
var uname=document.getElementById("txt_username").value;
var pwd=document.getElementById("txt_pwd").value;
$.ajax({
type : 'POST',
url : /Login', // Servlet URL
data:{
'uname':uname,
'pwd':pwd
},
success : function(data) {
if("SUCCESS"==data){
alert("Login Success!!");
} else {
alert("Invalid Login!!");
}
},
error : function(xhr, type) {
alert('server error occurred');
}
});
}
var uname=document.getElementById("txt_username").value;
var pwd=document.getElementById("txt_pwd").value;
$.ajax({
type : 'POST',
url : /Login', // Servlet URL
data:{
'uname':uname,
'pwd':pwd
},
success : function(data) {
if("SUCCESS"==data){
alert("Login Success!!");
} else {
alert("Invalid Login!!");
}
},
error : function(xhr, type) {
alert('server error occurred');
}
});
}
Following are the Screenshots For the Application,
I Hope this example will be useful for people learning PhoneGap,
Happy Coding!!
~Mayuri
Best Car pool Android Application Best Car Pool Application Source Code Download Here
Best Social Network Cordova Ionic Application Best Social Networking Source Code Cordova Ioinc Application Download Here
Best Android Application, Android Restaurant System Best Android Restaurant Application Source code download here
Best Android Application Android Chat Source code download Android Chat Source code download
Best Android Quiz Source Code Download Best Android Quiz Source Code Download here
More and Lots of useful Android source codes here Best Android Source codes download here
64 comments:
Hi Mayuri,
Can you share me your source code.
I am new to Phonegap and I want to do
Login page in Phonegap. I am unable to receive response from My servlet code. I have used your sample code posted here but I am always failed response.
Hi Mayuri,
Can you share me your source code.
I am new to Phonegap and I want to do
Login page in Phonegap. I am unable to receive response from My servlet code. I have used your sample code posted here but I am always failed response.
hello..
mam....
please...please...please...
send me this type of phonegap demo ...
I Want to learn this...
>shah.jai75@gmail.com
Thank you..mam..M waiting.... :)
Hi, First of all thanks for your good intention to publish a nice post. But please make a download link along with your post. So that the beginners can learn from your post.
Hi,
Thanks for the wonderful article. Can you post the entire code. I am getting server error. It doesn't work from browser too.
Regards,
Bala
thank u very much it works with little change
Hi Mayuri,
What servlet response are you getting .. i mean JSON or XML..also can you let us know what if the webservice is cross-domain how to get response from that..
Please reply..
Hi Mayuri,
Can you share me your source code.
Hi...
can u share this code ...
Hi Mayuri , can you please share this code . Because I'm newer in Android.
Hi Mayuri, can you please share this code. Regards.
Hi
I am new in phoneGap and i use the mobile jquery .
But it responsive time is very slow.
Can u suggest me any js to use it.
Great and Useful Article.
Java Online Training
Online Java Course
Java Course Online
J2EE training
online J2EE training
Best Recommended books for Spring framework
Java Interview Questions
Java Training Institutes in Chennai
Java Training in Chennai
J2EE Training in Chennai
java j2ee training institutes in chennai
Java Course in Chennai
The knowledge of technology you have been sharing thorough this post is very much helpful to develop new idea. here by i also want to share this.
Best Devops training in sholinganallur
Devops training in velachery
Devops training in annanagar
Devops training in tambaram
I appreciate that you produced this wonderful article to help us get more knowledge about this topic.
I know, it is not an easy task to write such a big article in one day, I've tried that and I've failed. But, here you are, trying the big task and finishing it off and getting good comments and ratings. That is one hell of a job done!
Selenium training in bangalore
Selenium training in Chennai
Selenium training in Bangalore
Selenium training in Pune
Selenium Online training
Inspiring writings and I greatly admired what you have to say , I hope you continue to provide new ideas for us all and greetings success always for you..Keep update more information..
python Course in Pune
python Course institute in Chennai
python Training institute in Bangalore
Great post! I am actually getting ready to across this information, It’s very helpful for this blog.Also great with all of the valuable information you have Keep up the good work you are doing well.
python Course in Pune
python Course institute in Chennai
python Training institute in Bangalore
Nice blog..! I really loved reading through this article. Thanks for sharing such a
amazing post with us and keep blogging...Also Checkout: cryptocurrency training in chennai | blockchain coaching in chennai | blockchain certification training in chennai | blockchain certification course in chennai
Very nice post here thanks for it .I always like and such a super contents of these post.Excellent and very cool idea and great content of different kinds of the valuable information's.
big data hadoop training in chennai
big data training in chennai chennai tamilnadu
spark training in chennai
Really useful information. Thank you so much for sharing.It will help everyone.Keep Post. RPA training in chennai | RPA training in Chennai with placement | UiPath training in Chennai | UiPath certification in Chennai with cost
Good job and thanks for sharing such a good blog You’re doing a great job. Keep it up !!
PMP Certification Fees | Best PMP Training in Chennai |
pmp certification cost in chennai | PMP Certification Training Institutes in Velachery |
pmp certification courses and books | PMP Certification requirements |
PMP Training Centers in Chennai | PMP Certification Requirements | PMP Interview Questions and Answers
Really Happy to say your post is very interesting. Keep sharing your information regularly for my future reference. Thanks Again.
Check Out:
big data training in chennai chennai tamil nadu
big data training in velachery
big data hadoop training in velachery
Attend The Python Training in Bangalore From ExcelR. Practical Python Training in Bangalore Sessions With Assured Placement Support From Experienced Faculty. ExcelR Offers The Python Training in Bangalore.
Just saying thanks will not just be sufficient, for the fantasti c lucidity in your writing. I will instantly grab Python classes in pune your rss feed to stay informed of any updates.
nice explanation, thanks for sharing, it is very informative
top 100 machine learning interview questions
top 100 machine learning interview questions and answers
Machine learning interview questions
Machine learning job interview questions
Machine learning interview questions techtutorial
Machine learning job interview questions and answers
Machine learning interview questions and answers online
Machine learning interview questions and answers for freshers
interview question for machine learning
machine learning interview questions and answers
Thank you for this informative blog
Top 5 Data science training in chennai
Data science training in chennai
Data science training in velachery
Data science training in OMR
Best Data science training in chennai
Data science training course content
Data science certification in chennai
Data science courses in chennai
Data science training institute in chennai
Data science online course
Data science with python training in chennai
Data science with R training in chennai
thanks for this informative article it is very useful
Machine learning taining in chennai
artificial intelligence and machine learning course in chennai
best machine learning training institute
top institutes for machine learning in chennai
machine learning course training institute in chennai
machine learning certification
machine learning training institutes
best institute to learn machine learning in chennai
machine learning course training
machine learning with r training in chennai
Attend The Data Analytics Course in Bangalore with Placement From ExcelR. Practical Data Analytics Course in Bangalore with Placement Sessions With Assured Placement Support From Experienced Faculty. ExcelR Offers The Data Analytics Course in Bangalore with Placement.
ExcelR Data Analytics Course in Bangalore with Placement
Your articles really impressed for me,because of all information so nice.informatica training in bangalore
These provided information was really so nice,thanks for giving that post and the more skills to develop after refer that post.dotnet training in bangalore
I gathered a lot of information through this article.Every example is easy to undestandable and explaining the logic easily.hadoop training in bangalore
Very useful and information content has been shared out here, Thanks for sharing it.Microsoft azure training in bangalore
This is really an awesome post, thanks for it. Keep adding more information to this.tableau training in bangalore
Really it was an awesome article,very interesting to read.You have provided an nice article,Thanks for sharing.angular 7 training in bangalore
Being new to the blogging world I feel like there is still so much to learn. Your tips helped to clarify a few things for me as well as giving.sap s4 hana simple finance training in bangalore
Linking is very useful thing.you have really helped lots of people who visit blog and provide them use full information.javascript training in bangalore
This is really an awesome post, thanks for it. Keep adding more information to this.html training in bangalore
Very useful and information content has been shared out here, Thanks for sharing it.sap hr training in bangalore
This is really an awesome post, thanks for it. Keep adding more information to this.html training in bangalore
I am happy for sharing on this blog its awesome blog I really impressed. thanks for sharing. Great efforts.
eTechno Soft Solutions offers the industry recognized Job Oriented Training in Bangalore that combines corporate training, online training, and classroom training effectively to fulfill the educational demands of the students worldwide.
I just loved your article on the beginners guide to starting a blog.If somebody take this blog article seriously in their life, he/she can earn his living by doing blogging.thank you for thizs article. blockchain online training
Not many writers can persuade me to their way of thinking. You've done a great job of doing that on many of your views here.
Best Data Science training in Mumbai
Data Science training in Mumbai
Wow!! Really a nice Article about Selenium. Thank you so much for your efforts. Definitely, it will be helpful for others. I would like to follow your blog. Share more like this. Thanks Again.
Java training in chennai | Java training in annanagar | Java training in omr | Java training in porur | Java training in tambaram | Java training in velachery
Greet post from blog. I always likes and such as super contents of these post. Kindly keep update like this.
AWS training in Chennai
AWS Online Training in Chennai
AWS training in Bangalore
AWS training in Hyderabad
AWS training in Coimbatore
AWS training
AWS online training
Thanks for Sharing This Article.It is very so much valuable content. I hope these Commenting lists will help to my website
blockchain online training
best blockchain online training
top blockchain online training
Attend The Business Analytics Course From ExcelR. Practical Business Analytics Course Sessions With Assured Placement Support From Experienced Faculty. ExcelR Offers The Data Analytics Course.
Business Analytics Course
I Want to leave a little comment to support and wish you the best of luck.we wish you the best of luck in all your blogging endeavors.
data science institute in bangalore
i am glad to discover this page : i have to thank you for the time i spent on this especially great reading !! i really liked each part and also bookmarked you for new information on your site.
data scientist course in bangalore
I want to leave a little comment to support and wish you the best of luck.we wish you the best of luck in all your blogging enedevors.
data analytics courses in bangalore
i am glad to discover this page : i have to thank you for the time i spent on this especially great reading !! i really liked each part and also bookmarked you for new information on your site.
cyber security training in bangalore
i am glad to discover this page : i have to thank you for the time i spent on this especially great reading !! i really liked each part and also bookmarked you for new information on your site.
data scientist course in bangalore
Extraordinary Blog. Provides necessary information.
german institute in Chennai
german coaching center in Chennai
Great post. keep sharing such a worthy information.
Google Analytics Training In Chennai
Google Analytics Online Course
Excellent blog and I really glad to visit your post. Keep continuing...
full form of csir
full form of tisco
full form of love
e v s full form
gnm full form
pfa full form
vc full form
what is the full form of ict
psb full form
nri college full form
Thanks for sharing such nice info. I hope you will share more information like this. please keep on sharing!
Python Training In Bangalore | Python Online Training
Artificial Intelligence Training In Bangalore | Artificial Intelligence Online Training
Data Science Training In Bangalore | Data Science Online Training
Machine Learning Training In Bangalore | Machine Learning Online Training
AWS Training In Bangalore | AWS Online Training
IoT Training In Bangalore | IoT Online Training
Blockchain Training in Bangalore| BlockchainOnline Training
This post is so interactive and informative.keep update more information...
Artificial Intelligence Course in Tambaram
Artificial Intelligence Course in Chennai
Great post. keep sharing such a worthy information.
Angularjs Training in Chennai
Angularjs Certification Online
Angularjs Training In Bangalore
Infycle offers the solitary AWS training in Chennai for the freshers, professionals, and students along with the additional course such as DevOps Training and Java training for making the candidate an all-rounder in the Software domain field. For a lucrative career, dial 7504633633, 7502633633.
Mindblowing blog very useful thanks
Digital Marketing Course in Porur
Digital Marketing Course in OMR
Your work is very good and I appreciate you and hopping for some more informative posts.
data scientist course
Post a Comment