Я пытаюсь отобразить содержимое моей базы данных на веб-странице, используя jsp. Она отображается пустой, кроме html-частей кода, таких как заголовки «id name» и т. Д. Я думаю, что мой код верен. Пожалуйста, помогите
Я пробовал одни и те же коды со многих веб-сайтов. К сожалению, все они заканчиваются одинаково
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@page import="java.sql.*"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<table class="table">
<thead>
<tr>
<th>ID</th>
<th>Name</th>
<th>Email</th>
<th>Phone</th>
<th>Address</th>
</tr>
</thead>
<tbody>
<%
String host="jdbc:mysql://localhost:3306/dbname";
Connection conn=null;
Statement stat=null;
ResultSet res=null;
try {
Class.forName("com.mysql.cj.jdbc.Driver");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
try{
conn=DriverManager.getConnection(host,"root","password");
stat=conn.createStatement();
String data="select * from emp";
res=stat.executeQuery(data);
while(res.next())
{%>
<tr>
<td><%=res.getInt(1) %></td>
<td><%=res.getString("name") %></td>
<td><%=res.getString("email") %></td>
<td><%=res.getString("phone") %></td>
<td><%=res.getString("address") %></td>
</tr>
<%
}
} catch (Exception e) {
e.printStackTrace();
}
%>
</tbody>
</table>
</html>
Только заголовки (или) имена таблиц в HTML-части кода отображаются навеб-страница