this is my code
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql" %>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<sql:setDataSource var="db"
driver="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost/dbase"
user="root"
password="1asulxayev" />
<sql:query var="select" dataSource="${db}">
select * from dtable
</sql:query>
<select name="lst">
<c:forEach var="result" items="${select.rows}">
<option>${result.name}</option>
</c:forEach>
</select>
<input type="submit" value="Fill" name="btn">
</body>
</html>
This time when page load dropdown list populate. but i want when button click populate dropdown list
Here is the sample code using AJAX. For more info read inline comments.
Servlet:
Fetch the data from the database in
doGet()
method and simply write a comma separated string the HTTP response and flush it to the client.HTML: