How to display data in the HTML page from the Database using Servlet ?
Asked
Active
Viewed 381 times
-4
-
just google once and you will get tons of example to use and modify according to it. – Samyak Upadhyay Feb 22 '18 at 06:50
1 Answers
0
Well It's a very silly question but since you have asked so I am writing answer here.
You can fetch the Data from the Database using JDBC and then use response printwriter to display it.
Sample Program
Connection con;
PrintWriter out = response.getWriter();
response.setContentType("text/html");
con = DriverManager.getConnection("jdbc:mysql://localhost:" + "3306" + "/" + "pinnnacledb1", "root", "");
String query = "Select * from table where something = ?";
PreparedStatement pst = currentCon.prepareStatement(query);
pst.setString(1, username);
ResultSet rs = pst.executeQuery();
while (rs.next())
{
//Your logic for display
out.println(<html>Whole html logic can be written here</html>);
}
So now run the servlet and result will be displayed on the browser.

Chetan Kumar
- 1,331
- 1
- 10
- 16