2017-10-08 1 views
-2

comment récupérer une table SQL à mon JSP sans utiliser JavaScript ou ajaxcomment récupérer un SQLTable à mon JSP

je veux tout le code JSP

<html> 
<head> 
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 
    <title>JSP Page</title> 
</head> 
<body> 

    <% 
     //i need to write the code here 
    %> 

</body> 
</html> 

Note: J'ai créé le sauver méthode au printemps et mise en veille prolongée, mais je ne sais pas comment récupérer les données

Répondre

0
Add this tag 

    <%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql" %> 

    // then DB details 

<sql:setDataSource 
     var="myDS" 
     driver="com.mysql.jdbc.Driver" 
     url="jdbc:mysql://localhost:3306/databaseName" 
     user="root" password="password" 
    /> 
    //Your query 
    <sql:query var="listDetails" dataSource="${myDS}" > SELECT * FROM TableName ; 
    </sql:query> 

    //Then comes view 
    <c:forEach var="listDetails" items="${listDetails.rows}"> 
     <tr> 
     <td><c:out value="${listDetails.id}" /></td> 
     </tr> 
    </c:forEach>