I am trying to connect to a database on button click on a jsp page. The value from the textbox of the html page should be captured and used to satisfy the conditions necessary to display the database values. I am using HTML,JSP,Jquery and Ajax. My database is MySql.

I have created a **'forgot password' **link which opens up a new webpage containing a textbox (to enter a mail address to which the password has to be sent) and a send button. How do I proceed with it?

I have tried using ajax and jquery on the jsp page to activate database on button click but they fail.

Please help!!!!!

Example codes are very much apprecited.

Recommended Answers

Given that 5 years ago I written [JSP database connectivity according to Model View Controller (MVC) Model 2] (http://www.daniweb.com/web-development/jsp/threads/141776/jsp-database-connectivity-according-to-model-view-controller-mvc-model-2)tutorial that sits on top of the JSP section it still amazes me that people are …

Jump to Post

All 3 Replies

Member Avatar

Please help!!!!!


Please post your code.

Need help in Ajax and send mail part of the code!!!


function emailAck()
//document.getElementById("mail").innerHTML="<b>Password has been sent to your mail</b>";
/*setTimeout(function() {
    window.location = 'http://localhost:8080/bank/main';
}, 3000);*/
    <title>Forgot Password</title>
<%@ include file="/template/banner.jsp" %> 
<p id="mail" name="mailtext"><b>Please Enter your Email</b></p>
<input type="text" id="email"/>
<input type="submit" value="Send" id="sendbtn" onclick="emailAck()" />
<div class="log"></div>
<script type = "text/javascript" src = "http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script type = "text/javascript">

$(function() {

$('#sendbtn').click(function() {

  // I want connect to database using ajax and jsp

                //Really not sure of the Ajax code....




return false;



//passwordAck.jsp containing database connection

<%@ page import="java.sql.*" %>
String content=request.getParameter("email");//email is value from the textbox on the other page
Connection con = null;
String url = "jdbc:mysql://localhost:3306/dbapp";
String driver = "com.mysql.jdbc.Driver";
String userName ="root";
String password="password";
Statement st;
con = DriverManager.getConnection(url,userName,password);
st = con.createStatement();
ResultSet rs = st.executeQuery("select Passwrd, from cust_login where email="'+content+'"");
    //send password to the specified mail
<form method="post" name="form">
<div align="center">
<p><b>Password has been sent to your mail</b></p>
<table border="0">

     catch(Exception e){
       Exception ex = e;
       out.println("Mysql Database Connection Not Found");

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.