JSP (Java Server Page) - Data source, para mostrar base de datos

 
Vista:
sin imagen de perfil
Val: 1
Ha mantenido su posición en JSP (Java Server Page) (en relación al último mes)
Gráfica de JSP (Java Server Page)

Data source, para mostrar base de datos

Publicado por David (1 intervención) el 22/06/2018 11:10:46
Hola buenos días:

A ver os comento el problema que tengo, estoy haciendo un formulario que me muestre los datos de una base de datos. Bien, pero me piden que lo haga con etiquetas, aqui es donde tengo el problema. Tengo hecho el formulario en un jsp, he creado la etiqueta tag file y la he vinculado con el tld. El problema que tengo es que en la tag file, no se como hacer que me muestre los datos de la base de datos. Os copio el código para ver si alguien me puede ayudar.

Un saludo.

Formulario:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql"%>
<%@ taglib prefix="tags" uri="/WEB-INF/tlds/Tags" %>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
 
        <table border="1">
            <tr>
                <th>CÓDIGO</th>
                <th>NOMBRE</th>
                <th>RESISTENCIA</th>
                <th></th>
            </tr>
            <tags:forMateriales var="material" dataSource="db/MATERIALES" >
 
                <tr>
                    <td>${material.codigo}</td>
                    <td>${material.nombre}</td>
                    <td>${material.resistencia}</td>
                    <c:url var="urlIndex" value="/index" >
                        <c:param name="codigo">${material.codigo}</c:param>
                    </c:url>
                    <td><a href="${urlIndex}">Modificar</a></td>
 
                </tr>
            </tags:forMateriales >
        </table>
    </body>
</html>

TLD:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
<?xml version="1.0" encoding="UTF-8"?>
<taglib version="2.1" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-jsptaglibrary_2_1.xsd">
  <tlib-version>1.0</tlib-version>
  <short-name>tags</short-name>
  <uri>/WEB-INF/tlds/Tags</uri>
  <tag-file>
    <name>forNuevoMateriales</name>
    <path>/WEB-INF/tags/forNuevoMateriales.tag</path>
  </tag-file>
  <tag-file>
    <name>forMateriales</name>
    <path>/WEB-INF/tags/forMateriales.tag</path>
  </tag-file>
</taglib>

TAG FILE:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
<%@tag description="put the tag description here" pageEncoding="UTF-8"%>
<%@ taglib prefix="tag" uri="/WEB-INF/tlds/Tags" %>
<%@ taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql" %>
<%@tag import="javax.servlet.jsp.jstl.sql.ResultSupport"%>
<%-- The list of normal or fragment attributes can be specified here: --%>
<%@attribute name="result" required="true" rtexprvalue="true" %>
<sql:query var="result" dataSource="db/MATERIALES">
    SELECT * FROM MATERIAL
</sql:query>
 
    <if test="${result.rowCount>0}">
    <table border="1">
        <tr>
            <c:forEach var="col" items="${result.columnNames}"
                       <th>${col}</th>
</foreach>
        </tr>
        <c:forEach var="fila" items="${result.rowsByIndex}"
                   <tr>
                   <c:forEach var="dato" items="${fila}">
                       <td>${dato}</td>
            </c:forEach>
            </tr>
</foreach>
    </table>
            </if>
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder