1
I am putting together a generic form for registration of legal and natural persons and the definition part of two RadioButton's
that change the fields, after completed they are sent to a Servlet
and then to a class DAO
, the form has different type fields CPF for PF and CNPJ for PJ, I have a condition in Servlet
that you need to validate the selected type in order to play the fields in the class Usuario()
, and I want to know how I can make this validation in JSP from the radio button?
Basic structure:
<form>
<!-- Tipo de Cadastro -->
<input id="radiopf" type="radio" name="Type" checked value="pessoaPF">
<label for="radiopf">Pessoa Fisica</label>
<input id="radiopj" type="radio" name="Type" value="pessoaPJ">
<label for="radiopj">Pessoa Juridica</label>
</form>
<!-- Formulário de Cadastro -->
<form id="frm" name="FormCadastro" action="Controle" method="POST">
<fieldset id = "PF">
<!-- Campos Pessoa Física -->
</fieldset>
<fieldset id = "PJ">
<!-- Campos Pessoa Jurídica-->
</fieldset>
<input type="submit" value="Gravar" name="Cadastrar" onclick="return Validate();" />
</form>
OBS: Validate();
is a validation in JavaScript
made before sending the data to the Servlet
checks data type, size, formatting, null fields etc.
Controle
is the Servlet
receiving the data via request.getParameter()
to send to the class DAO
.