0
I have a form and to update I have this code snippet. I can’t understand what he means. Like, if the student is not active in the system he puts value="true"? Otherwise it also puts value="true" but checked="checked". What does that mean?
<%if(aluno.getAtivo() == false){ %>
<input type="checkbox" id="ativo" name="ativo" value="true"/><br>
<%}else { %>
<input type="checkbox" id="ativo" name="ativo" value="true" checked="checked"/><br>
<%} %>
<input type="submit" value="Atualizar">
Follow full jsp page:
<%@page import="DAO.AlunoDAO"%>
<%@page import="MODEL.Aluno"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Atualizando aluno</title>
</head>
<body>
<% Aluno aluno = new AlunoDAO().find(Integer.parseInt(request.getParameter("id")));%>
<form action="alunoCONTROLLER" method="get">
<input type="hidden" name="operacao" value="atualizar">
<input type="hidden" name="id" value="<%=aluno.getId()%>">
<label for="name">Nome:</label>
<input type="text" id="nome" name="nome" value="<%=aluno.getNome()%>"/><br/>
<label for="telefone">Telefone:</label>
<input type="text" id="telefone" name="telefone" value="<%=aluno.getTelefone() %>"/><br/>
<label for="email">E-mail:</label>
<input type="text" id="email" name="email" value="<%=aluno.getEmail()%>" /><br>
<label for="endereco">Endereço:</label>
<input type="text" id="endereco" name="endereco" value="<%=aluno.getEndereco() %>"/><br>
<label for="matricula">Matricula</label>
<input type="text" id="matricula" name="matricula" value="<%=aluno.getMatricula() %>"/><br>
<label for="idade">Idade</label>
<input type="text" id="idade" name="idade" value="<%=aluno.getIdade() %>"/><br>
<label for="ativo">Ativo:</label>
<%if(aluno.getAtivo() == false){ %>
<input type="checkbox" id="ativo" name="ativo" value="true"/><br>
<%}else { %>
<input type="checkbox" id="ativo" name="ativo" value="true" checked="checked"/><br>
<%} %>
<input type="submit" value="Atualizar">
</form>
But the page is called refresh.jsp I don’t understand why I can’t chaamr de jsp...
– Aline
I didn’t understand this: vehicle=Car=Bicycle
– Aline
It wouldn’t be: vehicle=Bicycle?
– Aline
Hello @Alinegonzaga. I don’t understand. I just said that your question is purely HTML, has no relation to JSP. From what I read of your question, you are doubtful about the meaning of the attributes of an input checkbox.
– cantoni
vehicle=Bicycle is what was received on the server side. It is only received if the checkbox is checked. Note that in the first example, only the checkbox car is marked, so get only vehicle=Car. After I comment that the checkbox Bike has been marked, then it is received from the server side vehicle=Car & vehicle=Bike, because the two checkboxes are marked. When I speak on the server side, it can be PHP, JAVA, C#, any WEB language.
– cantoni
This Bike is an attribute of some class in java?
– Aline
@Alinegonzaga, so better not mark the answer as correct. I put the HTML tag and will certainly find someone who will give you another explanation. This is important in Sopt. Often knowledge is in several responses.
– cantoni
@Alinegonzaga, my main goal was to show you that the value of the value attribute is unrelated to the checkbox state (marked or unchecked). Value can be whatever you want it to be. It can even be the value of an attribute of a Java object. In your case, as you are talking about Active Student, the true is the most correct. In the example I posted, true no longer serves, because we are talking about car.
– cantoni
No, I’ll study what you wrote after right. Thanks to Julie.
– Aline
In the case of your example there then the two would be marked?
– Aline
In the example, only one is marked, the Car, because it has the attribute checked. Note that this way, the server receives only vehicle=Car. Soon after I mentioned that I clicked on the Bike. As now the two are marked, then the server gets vehicle=Vehicle=Bike.
– cantoni
AHHHHHHHHHHHHHHHHH Now I understand. Finally...
– Aline