Duvidas com Servlets, por favor

Criei um projeto EBJ, onde neste mapei meu Banco de Dados(postgre) , criando assim minhas classes de persistências. Abaixo um exemplo da minha classe de persistência que mapeio do BD, Professor.
package br.ifet.campos.info.taii20082n.fiage.model.persistence;

import java.io.Serializable;
import java.util.Set;

import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.OneToMany;

@Entity
public class Professor implements Serializable {
@Id
private String matricula;

private String telefone;

private String celular;

private String rg;

private String regimetrabalho;

private String email;

private String cpf;

private String nome;

private String titulo;

@OneToMany(mappedBy="matricula")
private Set<Leciona> lecionaCollection;



@OneToMany(mappedBy="matricula")
private Set<Endereco> enderecoCollection;

@OneToMany(mappedBy="matricula")
private Set<Professorcoordenacao> professorcoordenacaoCollection;

@OneToMany(mappedBy="matricula")
private Set<Competencia> competenciaCollection;

private static final long serialVersionUID = 1L;

public Professor() {
	super();
}

public String getMatricula() {
	return this.matricula;
}

public void setMatricula(String matricula) {
	this.matricula = matricula;
}

public String getTelefone() {
	return this.telefone;
}

public void setTelefone(String telefone) {
	this.telefone = telefone;
}

public String getCelular() {
	return this.celular;
}

public void setCelular(String celular) {
	this.celular = celular;
}

public String getRg() {
	return this.rg;
}

public void setRg(String rg) {
	this.rg = rg;
}

public String getRegimetrabalho() {
	return this.regimetrabalho;
}

public void setRegimetrabalho(String regimetrabalho) {
	this.regimetrabalho = regimetrabalho;
}

public String getEmail() {
	return this.email;
}

public void setEmail(String email) {
	this.email = email;
}

public String getCpf() {
	return this.cpf;
}

public void setCpf(String cpf) {
	this.cpf = cpf;
}

public String getNome() {
	return this.nome;
}

public void setNome(String nome) {
	this.nome = nome;
}

public String getTitulo() {
	return this.titulo;
}

public void setTitulo(String titulo) {
	this.titulo = titulo;
}

public Set<Leciona> getLecionaCollection() {
	return this.lecionaCollection;
}

public void setLecionaCollection(Set<Leciona> lecionaCollection) {
	this.lecionaCollection = lecionaCollection;
}



public Set<Endereco> getEnderecoCollection() {
	return this.enderecoCollection;
}

public void setEnderecoCollection(Set<Endereco> enderecoCollection) {
	this.enderecoCollection = enderecoCollection;
}





public Set<Professorcoordenacao> getProfessorcoordenacaoCollection() {
	return this.professorcoordenacaoCollection;
}

public void setProfessorcoordenacaoCollection(Set<Professorcoordenacao> professorcoordenacaoCollection) {
	this.professorcoordenacaoCollection = professorcoordenacaoCollection;
}


public Set<Competencia> getCompetenciaCollection() {
	return this.competenciaCollection;
}

public void setCompetenciaCollection(Set<Competencia> competenciaCollection) {
	this.competenciaCollection = competenciaCollection;
}

}

Dentro do meu projeto WEB, criei um Principal Servlet
Abaixo o seu código:

package br.ifet.campos.info.taii20082n.fiage.web.control;

import java.io.IOException;
import java.lang.reflect.InvocationTargetException;

import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import br.ifet.campos.info.taii20082n.fiage.web.control.helper.GenericHelper;

/**

  • Servlet implementation class PrincipalServlet
    */
    public class PrincipalServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;

    /**

    • @see HttpServlet#HttpServlet()
      */
      public PrincipalServlet() {
      super();
      // TODO Auto-generated constructor stub
      }

    /**

    • @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
    •  response)
      

    */
    protected void doGet(HttpServletRequest request,
    HttpServletResponse response) throws ServletException, IOException {
    // TODO Auto-generated method stub
    }

    /**

    • @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
    •  response)
      

    */
    protected void doPost(HttpServletRequest request,
    HttpServletResponse response) throws ServletException, IOException {

     String nomeForm = request.getParameter("nomeForm");
    
     String helper = nomeForm.substring(0, nomeForm.indexOf(".")).concat(
     		"Helper");
     String metodo = nomeForm.substring(nomeForm.indexOf(".") + 1, nomeForm
     		.length());
    
     System.out.println(helper + " "+metodo);
     
     
     GenericHelper gHelper = null;
    
     Object obj = null;
     try {
     	obj = Class.forName(
     			"br.ifet.campos.info.taii20082n.fiage.web.control.helper."
     					.concat(helper)).newInstance();
     } catch (InstantiationException e1) {
     	// TODO Auto-generated catch block
     	e1.printStackTrace();
     } catch (IllegalAccessException e1) {
     	// TODO Auto-generated catch block
     	e1.printStackTrace();
     } catch (ClassNotFoundException e1) {
     	// TODO Auto-generated catch block
     	e1.printStackTrace();
     }
    
     gHelper = (GenericHelper) obj;
    
     try {
     	@SuppressWarnings("unused")
     	Object i = gHelper.getClass().getMethod(metodo,
     			HttpServletRequest.class).invoke(gHelper, request);
     } catch (IllegalArgumentException e) {
     	// TODO Auto-generated catch block
     	e.printStackTrace();
     } catch (SecurityException e) {
     	// TODO Auto-generated catch block
     	e.printStackTrace();
     } catch (IllegalAccessException e) {
     	// TODO Auto-generated catch block
     	e.printStackTrace();
     } catch (InvocationTargetException e) {
     	// TODO Auto-generated catch block
     	e.printStackTrace();
     } catch (NoSuchMethodException e) {
     	// TODO Auto-generated catch block
     	e.printStackTrace();
     }
    
     
    
     response.setContentType("text/html");
     ServletOutputStream out = response.getOutputStream();
     
    
     // TODO Auto-generated method stub
    

    }

}

  • Para cada Classe que eu Tenho eu Criei ?NomeClasseHelper?.
    Abaixo exemplo da classe ProfessorHelper

package br.ifet.campos.info.taii20082n.fiage.web.control.helper;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.EntityTransaction;
import javax.persistence.Persistence;
import javax.servlet.http.HttpServletRequest;

import br.ifet.campos.info.taii20082n.fiage.model.persistence.Professor;
import br.ifet.campos.info.taii20082n.fiage.model.persistence.Coordenacao;
import br.ifet.campos.info.taii20082n.fiage.model.persistence.Professorcoordenacao;

public class ProfessorcoordenacaoHelper extends GenericHelper{

private static final long serialVersionUID = 1L;
EntityManagerFactory emf = Persistence.createEntityManagerFactory("FIAGEEJB");
EntityManager em = emf.createEntityManager();

public void Excluir(HttpServletRequest request) {
	// TODO Auto-generated method stub

}

public void Salvar(HttpServletRequest request) {
	Professorcoordenacao profcoord = new Professorcoordenacao();
	profcoord.setCodigo(request.getParameter("codigo"));
	profcoord.setCargahoraria(request.getParameter("cargahoraria"));
	profcoord.setMatricula(em.find(Professor.class, "matricula"));
	profcoord.setCodcoord(em.find(Coordenacao.class, "coddisc"));
	
	EntityTransaction trans = em.getTransaction();

	trans.begin();
	em.persist(profcoord);
	trans.commit();
	System.out.println("entrei");

}

public void Pesquisa(HttpServletRequest request) {
	
	
}
  • E criei o formulário de Cadastro como o exemplo abaixo:
    <%@ page language=“java” contentType="text/html; charset=ISO-8859-1"
    pageEncoding=“ISO-8859-1”%>

<%@page import=“br.ifet.campos.info.taii20082n.fiage.model.persistence.*”%>

Cadastro de Cidades <%@ page import="br.ifet.campos.info.taii20082n.fiage.model.persistence.* %> <% Professor professor =(Professor) session.getAttribute("professores"); String matricula ="&nbsp"; String nome = "&nbsp"; String titulo = "&nbsp"; String rg = "&nbsp"; String cpf = "&nbsp"; String email = "&nbsp"; String telefone = "&nbsp"; String celular = "&nbsp"; String regimetrabalho = "&nbsp";

if (professor!= null)
{
matricula =professor.getMatricula();
nome=professor.getNome();
titulo=professor.getTitulo();
rg = professor.getRg();
cpf =professor.getCpf();
email=professor.getEmail();
telefone=professor.getTelefone();
celular=professor.getCelular();
regimetrabalho=professor.getRegimetrabalho();

}
%>

Cadastro de Professores


  Matricula: size="20">
  Nome: size="20">
  Titulo: size="20">
  RG: size="20">
  CPF: size="20">
  E-mail: size="20">
  Telefone: size="20">
  Celular: size="20">
  Regime Trabalho: size="20">
 

	</td>
</tr>

-Minha Dúdida é que para cada um desses eu vou ter que ter consultas, ou seja vou ter formulários de Consultas e não estou conseguindo implemetar isso. Um exemplo é o seguinte vou ter um formulário de consulta de professores. E com base do conteúdo preenchido vou listar esses dados como resposta se existir, senão terei que dar uma mensagem de dados não encontrados.
Um exemplo:
Buscar Professor
Todos Existentes
Matricula:
Nome:
[ok]
Se a opção for todas, listarei todos existentes no BD.Caso, exista um professor com a matricula ou nome cadastrada terei que listar dessa forma na tela.
Carlos Lacerda Ribeiro

  • A partir daí o usuário poderá clicar no nome desejado e seguinte tela apresentar:

Matricula: 2354-6
Nome: Carlos Lacerda Ribeiro
Titulação: Mestre
[Atualizar Registro] [Apagar Registro] [Excluir Registro]

  • Sei que as dúvidas são muitas porém queria mesmo só exemplos de como implementar…

Por favor alguém da um help!

Brother, use a tag Code para escrever seu código, dessa forma ficará mais fácil entender seu problema. Tenta sintetizar um pouco mais qual é a sua dúvida.

[code]ffdsd

Minha dúvida é em relação as tipos de buscas de acordo com as classe ProfessorHelper e com a Classe principal Servlet. Não estou conseguindo implementar isso.
Ve se da uma ajuda ai…