Lógica de tabelas em jsp[resolvido]

5 respostas
thomazaudio

Estou querendo fazer o seguinte:
Em uma página o usuário entra com o número de linhas e colunas da tabela, e em outra página aparece a tabela colunas x linhas, com um campo de entrada de texto em cada célula.

5 Respostas

E

e qual sua dúvida mais especificamente?

thomazaudio

Exemplo,essa tabela tem 2 colunas e 4 linhas,mas estou querendo fazer de jeito que o usuário entre com o número de linhas e colunas.

<tr>
            <td><input type="text"/></td>
            <td><input type="text"/></td>
            
            
            </tr>
            <tr>
                <td><input type="text"/></td>
                <td><input type="text"/></td>
                </tr>
                 <tr>
                <td><input type="text"/></td>
                <td><input type="text"/></td>
                </tr>
        
    </table>
E

tá, mas o que você já conseguiu fazer?

H

Opa,

Tente algo nesse estilo:

String tabela = "<table>";
for(int i = 1; i <= 4; i++) { // Linhas
	tabela += "<tr>";
	for(int j = 1; j <= 3; j++) { // Colunas
		tabela += "<td>";
			tabela += "<input type=\"text\" name=\"textfield" + i + "-" + j + "\" />";
		tabela += "</td>";
	}
	tabela += "</tr>";
}
tabela += "</table>";

Valeu

thomazaudio
Valeu! Consegui dessa forma
<% 
        int colunas= Integer.parseInt(request.getParameter("colunas"));
int linhas= Integer.parseInt(request.getParameter("linhas"));
%>
        
       <table>
           <tr>
        <% for(int x = 1 ; x<= colunas;x++){%> 
        <th><input type="text"/></th>
        <%}%>
            </tr>

        <% for(int x2=1 ;x2<=linhas -1;x2++){%>
        <tr>
           <%for(int x3 =1; x3<=colunas ;x3++){%>
           <td><input type="text"/></td>
           <%}%>
            </tr>
        <%}%>
            
            
            
        </table>
Criado 8 de janeiro de 2012
Ultima resposta 8 de jan. de 2012
Respostas 5
Participantes 3