1

Tengo que representar un tablero de ajedrez utilizando la tecnología EL JSTL de Java. quiero hacer que cuando la fila y la columna suman impar me ponga el fondo negro y cuando es par me lo ponga blanco. Con el código que pongo a continuación me salen todos los cuadros negros y no entiendo el por qué.
Gracias de antemano.

    <%@ taglib prefix= "v" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Tablero ajedrez</title>
</head>
<body>
    <table style="width:300px; height:300px; border: 1px solid red;">
        <v:forEach var="i" begin="1" end="8" step="1">
            <tr style="border: 1px solid red;"><v:forEach var="j" begin="1" end="8" step="1">
                <v:choose>
                    <v:when test="(i+j)%2==0"><td style="background: white;"></td></v:when>
                    <v:otherwise><td style="background: black;"></td></v:otherwise>
                </v:choose>                 
            </v:forEach></tr>
        </v:forEach>
    </table>

</body>
</html>

1 respuesta 1

0

Necesitas indicar que la expresión no es un literal, sino que debe ser procesada, usando la notación ${...}:

<v:when test="${(i+j)%2==0}">
1

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge you have read our privacy policy.

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.