Combo box no html carregar campo no combo

1 resposta
E

<%@page contentType=“text/html”%>
<%@page pageEncoding=“UTF-8”%>
<%@
include file=“ServerConfiguration.jsp”
%>

<%@
page import=“org.firebirdsql.jdbc.,org.firebirdsql.logging.Logger,java.sql.

%>

<%

Class.forName(“org.firebirdsql.jdbc.FBDriver”);

Connection aConnection = DriverManager.getConnection(DatabaseAddr,UserName, Password);

Statement stmt = aConnection.createStatement();

String Sql=“Select nomecidade from cidade where idcidade=28”;
ResultSet aQuery=stmt.executeQuery(Sql);

%>

<%–
The taglib directive below imports the JSTL library. If you uncomment it,
you must also add the JSTL library to the project. The Add Library… action
on Libraries node in Projects view can be used to add the JSTL 1.1 library.
–%>
<%–
<%@taglib uri=“http://java.sun.com/jsp/jstl/core” prefix=“c”%>
–%>

Cadastro de Movimentações de Usuário

Tipo de Movimentacao
1 - inclusao de Titular 2 - Inclusao de Dependente 3 - Exclusao de Titular 4 - Exclusao de Dependente 5 - Solicitacao de 2 via 8 - Alteracao de Dados

Nome

Tp Usuario

Grupo Setor
local Atendimento
<%

while (aQuery.next())

{

%>

<%=aQuery.getString("nomecidade")%>

<%

}
%>

<%--
This example uses JSTL, uncomment the taglib directive above.
To test, display the page like this: index.jsp?sayHello=true&name=Murphy
--%>
<%--
<c:if test="${param.sayHello}">
    <!-- Let's welcome the user ${param.name} -->
    Hello ${param.name}!
</c:if>
--%>

</body>

Esta fazendo a conexao certinho com o banco, mas tenho uma tabela chamada cidade, que gostaria de carregar em um combo do html
Como eu faco para carregar o campo nomecidae no combo?

1 Resposta

wellington_marinheir

Ola Evandro

<% 
while (aQuery.next()) 
{ 

%> 


<select name="atendimento"> 
<option><%=aQuery.getString("nomecidade")%></option> 
</select> 


<% 

} 
%>

No código que voce colocou acima, a linha

deve ficar antes do inicio do loop
A a linha após o fechamento do loop, com isto, o sistema faz o seguinte:
abre a opção select
varre a base de dados colocando o nome das cidades como opção
encerra o select…
O codigo seria assim:

<select name="atendimento"> 
<% 
while (aQuery.next()) 
{ 

%> 
<option value=><%=aQuery.getString("nomecidade")%>><%=aQuery.getString("nomecidade")%></option> 
<% 
}
</select>

Não esquecer de incluir o parametro value que será o responsavel por enviar o valor escolhido para a proxima etapa do seu formulario.

Wellington Marinheiro

Criado 11 de novembro de 2006
Ultima resposta 12 de nov. de 2006
Respostas 1
Participantes 2