JSP and Servlet Form Submission without page refresh show results on the same page using Jquery AJAX
Code Snippet
HTML Form
<form id='ajaxform' name='ajaxform' action='ajaxformexample' method='post'>
First Name: <input type='text' id='firstname' name='firstname' size='30' required/><br/>
Last Name: <input type='text' id='lastname' name='lastname' size='30'required/><br/>
Email: <input type='email' id='emailid' name='emailid' size='30'required/><br/>
Password: <input type='password' id='pwd' name='pwd' size='30'required/><br/>
<input type='Submit'/>
<div id='content'>
</div>
</form>
the above HTML Form uses post method and url servlet redirect to "ajaxformexample"
Javascript Code
var form = $('#ajaxform'); // id of form tag
form.submit(function () {
$.ajax({
type: form.attr('method'), //post method
url: form.attr('action'), //ajaxformexample url
data: form.serialize(), // serialize input data values
success: function (data) {
var result=data;
$('#content').html(result); //showing result
}
});
return false; // not refreshing page
});
the above javascript code uses Ajax jquery concept and parameters type, url,data, and finally success function to show result from specified action SERVLET performed results back to same page and in the below code snippet Servlet uses doPost method to get values in the input fields;
public void doPost(HttpServletRequest req, HttpServletResponse resp)
throws IOException {
resp.setContentType("text/html");
PrintWriter out=resp.getWriter();
String fname= req.getParameter("firstname");
String lname= req.getParameter("lastname");
String email= req.getParameter("emailid");
String password= req.getParameter("pwd");
out.println("<br/><br/>First Name = "+fname+"<br/><br/>Last Name = "+lname+"<br/><br/>Email = "+email+"<br/><br/>Password = "+password);
}
index.jsp Page
servlet Java
Output
Thank You Very Much ....
ReplyDeleteyour welcome
Deleteactually i used this code and when i enter the submit button the page get refreshed...pls suggest the solution
ReplyDeletehave u used jquery code which will return false as below code ?
Deletevar form = $('#ajaxform'); // id of form tag
form.submit(function () {
$.ajax({
type: form.attr('method'), //post method
url: form.attr('action'), //ajaxformexample url
data: form.serialize(), // serialize input data values
success: function (data) {
var result=data;
$('#content').html(result); //showing result
}
});
return false; // not refreshing page
});
And If I want to show in the same form, How I can do that?
ReplyDeletethis only show in the same form
DeleteThanks a ton :)
ReplyDeleteyour welcome
DeleteHi, why it opening the page: http://localhost:8080/SisGestWeb/AjaxformexampleServlet instead of displaying the result in the same page?
ReplyDeletethnx so much...nicly explaned for beginners very usefulll
ReplyDeleteIt doesn't work. The code reloads the page and open another page. Someone can help me ?
ReplyDeletei need a deep explanation which is most helpful for me to develop a technical skills quickly.
ReplyDeleteJava Training in Chennai
Suppose we used bootstrap and we want show any error then how i show ...in simple words vaidation/.
ReplyDeletecan you provide me jquery code that make crud operation in SPA.
ReplyDeletefor Servlet compulsary
ReplyDeleteThanks a lot very much for the high quality and results-oriented help. I won’t think twice to endorse your blog post to anybody who wants and needs support about this area.
ReplyDeleteDigital Marketing Training in Bangalore
digital marketing training in tambaram
digital marketing training in annanagar
digital marketing training in marathahalli
digital marketing training in rajajinagar
Digital Marketing online training
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.
ReplyDeletepython training in OMR
python training in Bangalore
python training in Bangalore
Excellent post!!!. The strategy you have posted on this technology helped me to get into the next level and had lot of information in it.
ReplyDeleteData Science training in kalyan nagar
Data Science training in OMR
selenium training in chennai
Data Science with Python training in chenni
Data Science training in chennai
Data science training in velachery
Your very own commitment to getting the message throughout came to be rather powerful and have consistently enabled employees just like me to arrive at their desired goals.
ReplyDeletejava training in chennai | java training in bangalore
java training in tambaram | java training in velachery
Nice information, valuable and excellent design, as share good stuff with good ideas and concepts, lots of great information and inspiration, both of which I need, thanks to offer such a helpful information here.
ReplyDeleteonline Python certification course | python training in OMR | Python training course in Chennai
Thanks for taking the time to discuss this, I feel strongly about it and love learning more on this topic.
ReplyDeleteJava training in Rajaji nagar | Java training in Kalyan nagar
Java training in Kalyan nagar | Java training in Jaya nagar
All are saying the same thing repeatedly, but in your blog I had a chance to get some useful and unique information, I love your writing style very much, I would like to suggest your blog in my dude circle, so keep on updates.
ReplyDeleteData Science Training in Indira nagar
Data Science training in marathahalli
Data Science Interview questions and answers
This is the best article on recent technology. Thanks for taking your own time to share your knowledge,
ReplyDeleteselenium Training in Chennai
Selenium Training Chennai
iOS Training in Chennai
iOS Training Institutes in Chennai
JAVA J2EE Training Institutes in Chennai
Java course
ReplyDeleteWhoa! I’m enjoying the template/theme of this website. It’s simple, yet effective. A lot of times it’s very hard to get that “perfect balance” between superb usability and visual appeal. I must say you’ve done a very good job with this.
AWS Training in BTM Layout |Best AWS Training in BTM Layout
AWS Training in Marathahalli | Best AWS Training in Marathahalli
Selenium Interview Questions and Answers
AWS Tutorial |Learn Amazon Web Services Tutorials |AWS Tutorial For Beginners
I believe there are many more pleasurable opportunities ahead for individuals that looked at your site.
ReplyDeleteJava training in Chennai | Java training institute in Chennai | Java course in Chennai
Java training in Bangalore | Java training in Electronic city
Java training in Bangalore | Java training in Marathahalli
Java training in Bangalore | Java training in Btm layout
Very well written blog and I always love to read blogs like these because they offer very good information to readers with very less amount of words....thanks for sharing your info with us and keep sharing.
ReplyDeleteangularjs Training in chennai
angularjs Training in chennai
angularjs-Training in tambaram
angularjs-Training in sholinganallur
angularjs-Training in velachery
angularjs-Training in pune
Thanks for taking the time to discuss this, I feel strongly about it and love learning more on this topic.
ReplyDeleteangularjs Training in chennai
angularjs-Training in tambaram
angularjs-Training in sholinganallur
angularjs-Training in velachery
angularjs-Training in pune
Wonderful article, very useful and well explanation. Your post is extremely incredible. I will refer this to my candidates...
ReplyDeleteJava training in Chennai | Java training in Omr
Oracle training in Chennai
Java training in Chennai | Java training in Annanagar
Java training in Chennai | Java training institute in Chennai | Java course in Chennai
Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog. Really very informative post you shared here. Kindly keep blogging.
ReplyDeleteDevops online Training
Online DevOps Certification Course - Gangboard
I would assume that we use more than the eyes to gauge a person's feelings. Mouth. Body language. Even voice. You could at least have given us a face in this test.
ReplyDeletepython training in chennai
python course institute in chennai
This blog is the general information for the feature. You got a good work for these blog.We have a developing our creative content of this mind.Thank you for this blog. This for very interesting and useful.
ReplyDeleteData Science Training in Chennai | Best Data science Training in Chennai
Data Science training in kalyan nagar
Data science training in Bangalore | Data Science training institute in Bangalore
Data Science training in marathahalli | Data Science training in Bangalore
Data Science interview questions and answers
Data science training in jaya nagar | Data science Training in Bangalore
Great Article… I love to read your articles because your writing style is too good, its is very very helpful for all of us and I never get bored while reading your article because, they are becomes a more and more interesting from the starting lines until the end.
ReplyDeleteangularjs-Training in pune
angularjs Training in bangalore
angularjs Training in bangalore
angularjs Training in chennai
automation anywhere online Training
angularjs interview questions and answers
Nice post. Thanks for sharing.
ReplyDeleteIELTS Tambaram
IELTS Coaching in Chrompet
IELTS Classes near Chennai Tambaram
IELTS Coaching Center in Chennai Adampakkam
Best IELTS Coaching Institute in Velachery
IELTS Coaching in Velachery
IELTS Classes in Velachery
Really very nice blog information for this one and more technical skills are improve,i like that kind of post.
ReplyDeleterpa training in bangalore | best rpa training in bangalore
rpa online training
Really very nice blog information for this one and more technical skills are improve,i like that kind of post.
ReplyDeleterpa training in bangalore | best rpa training in bangalore
rpa online training
Very nice post here and thanks for it .I always like and such a super contents of these post.
ReplyDeleteExcellent and very cool idea and great content of different kinds of the valuable information's.
Java training in Bangalore
Really great post, I simply unearthed your site and needed to say that I have truly appreciated perusing your blog entries.
ReplyDeleteData science course in bangalore
Very nice post with lots of information. Thanks for sharing this updates.
ReplyDeleteMicrosoft Azure Training in Chennai
Azure Training
Data Science Course in Chennai
Data Science Training in Chennai
DevOps certification in Chennai
DevOps Training in Chennai
Azure Training in OMR
Azure Training in Porur
Your good knowledge and kindness in playing with all the pieces were very useful. I don’t know what I would have done if I had not encountered such a step like this.
ReplyDeletedevops online training
aws online training
data science with python online training
data science online training
rpa online training
Really very happy to say that your post is very interesting. I never stop myself to say something about it. You did a great job. Keep it up.
ReplyDeleteWe have an excellent IT courses training institute in Hyderabad. We are offering a number of courses that are very trendy in the IT industry. For further information, please once go through our site.
AWS Training In Hyderabad
The strategy you have posted on this technology helped me to get into the next level and had lot of information in it.data science course in Hyderabad
ReplyDeleteThank you for posting informative insights, I think we have got some more information to share with! Do check out
ReplyDeleteoracle training in chennai and let us know your thoughts. Let’s have great learning!
thank you so much
ReplyDeletehow do I clear the form fields after submission?
ReplyDeleteI enjoy it for creating the details, keep up the truly amazing perform continuing
ReplyDeletedata scientist training in hyderabad
Finish the Selenium Training in Chennai from Infycle Technologies, the best software training institute in Chennai which is providing professional software courses such as Data Science, Artificial Intelligence, Java, Hadoop, Big Data, Android, and iOS Development, Oracle, etc with 100% hands-on practical training. Dial 7502633633 to get more info and a free demo and to grab the certification for having a peak rise in your career.
ReplyDelete