أنشئ حسابًا أو سجّل الدخول للانضمام إلى مجتمعك المهني.
The JavaServer Pages Standard Tag Library (JSTL) is a collection of useful JSP tags which encapsulates core functionality common to many JSP applications. JSTLhas support for common, structural tasks such as iteration and conditionals, tags for manipulating XML documents, internationalization tags, and SQL tags.
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql"%>
define datasource inside web.xml so all jsp files access that database easily
web.xml
<context-param>
<param-name>javax.servlet.jsp.jstl.sql.dataSource</param-name>
<param-value>jdbc:mysql://localhost:3306/dbname,
com.mysql.jdbc.Driver,username,password </param-value>
</context-param>
showData.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql"%>
<!DOCTYPE html>
<html>
<body>
<sql:query>select Message from test<sql:query>
<p>Inside query tag you have to write query and parameter if you want.
and access you resultset using forEach loop </p>
<c:forEach var="row" items="${result.rows }">
<c:out value="${row.Message }"></c:out>
</c:forEach>
</body>
</html>