Ver Mensaje Individual
  #3 (permalink)  
Antiguo 13/03/2009, 08:12
Pelirr
 
Fecha de Ingreso: diciembre-2008
Mensajes: 233
Antigüedad: 15 años, 5 meses
Puntos: 1
Respuesta: problema con dto en servlet

Hola, este es el código de mi servlet:

package es.BBDDCaja.cajaelena.Web;

import java.rmi.RemoteException;
import java.io.IOException;
import java.util.ArrayList;
import java.lang.*;

import javax.ejb.CreateException;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.rmi.PortableRemoteObject;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import es.BBDDCaja.cajaelena.dto.clientsDto;
import es.BBDDCaja.cajaelena.facade.Home.clientsFacade;
import es.BBDDCaja.cajaelena.facade.Home.clientsFacadeHom e;
import es.BBDDCaja.cajaelena.facade.Remote.clientsFacadeB ean;

/**
* @web.servlet name = "PedirConfClienteServlet"
* display-name = "PedirConfClienteServlet"
* @web.servlet-init-param name = "SCajaElena.jndi.context"
* value = "ejb/es.BBDDCaja.cajaelena.Home/clientsFacadeHome"
* @web.servlet-mapping "/doPedirConfCliente"
*/
public class PedirConfClienteServlet extends HttpServlet {

private boolean initialized;
private ArrayList initErrors;
private HttpServlet servlet;
private String RESULT_URL,name,lastname1,lastname2,adress,birthda y,phone;
private ArrayList errors;
private clientsFacadeHome clientHome;

/** Constructor for IntrodDatosClienteServlet
*/
public PedirConfClienteServlet(){
super();
}

public void doGet(
HttpServletRequest theRequest,
HttpServletResponse theResponse)
throws ServletException, IOException{

if(!initialized){
ViewDispatcher.displayErrors(theRequest, theResponse, initErrors);
}
try{
doPedirConfCliente(theRequest,theResponse);
}
catch (Exception ex){
//top-level exception handler
ViewDispatcher.displayError(theRequest, theResponse, ex.toString());
}
}

public void doPost(
HttpServletRequest theRequest,
HttpServletResponse theResponse)
throws ServletException, IOException{

doGet (theRequest,theResponse);
}

public void init(){
String SCajaElenaJNDIContext =
getServletConfig().getInitParameter("SCajaElenaJND IContext");
String errorMsg = null;
boolean hasError = false;

initErrors = new ArrayList();

if (SCajaElenaJNDIContext == null){
errorMsg = "Error: undefined servlet property \"SCajaElena.jndi.context\".";
log(errorMsg);
hasError = true;
initErrors.add(errorMsg);
}
if (!hasError){
try{
Controller(this,SCajaElenaJNDIContext);
}
catch (Exception ex){
log (ex.toString());
initErrors.add(ex.toString());
hasError = true;
}
}
if (!hasError){
initialized = true;
}
}

public void Controller(
HttpServlet theServlet,
String theJNDIName)
throws NamingException {

servlet = theServlet;
}

public void doPedirConfCliente(
HttpServletRequest theRequest,
HttpServletResponse theResponse){

System.out.println("#doPedirConfCliente");
try{
populate(theRequest);
//perform transaction using IntrodDatosCliente EJB
try{
theRequest.setAttribute("confname", name);
theRequest.setAttribute("conflastname1", lastname1);
theRequest.setAttribute("conflastname2", lastname2);
theRequest.setAttribute("confadress", adress);
theRequest.setAttribute("confphone", phone);
theRequest.setAttribute("confbirthday", birthday);
ViewDispatcher.includeRequest(theRequest, theResponse, RESULT_URL);
}
catch (Exception ex){
ViewDispatcher.displayError(theRequest, theResponse, "Error creating IntrodDatosCliente");
}
}
catch (NamingException e){
e.printStackTrace();
}

//terminate operation if errors
if (hasErrors()){
ViewDispatcher.displayErrors(theRequest, theResponse, getErrors());
}
}

public void populate (HttpServletRequest theRequest) throws NamingException{
int phoneint;

phoneint=(Integer.valueOf(phone)).intValue();

clientsDto clients = new clientsDto();
clients.setName(name);
clients.setFirstlastname(lastname1);
clients.setSecondlastname(lastname2);
clients.setAdress(adress);
clients.setTelephone(phoneint);

Context ctx = getInitialContext();
Object home = ctx.lookup("SCajaElenaClientsEjb");
clientHome = (clientsFacadeHome)home;
clientsFacade clientmethod = null;

clientmethod = clientHome.create();
//LA SIGUIENTE LINEA ES LA QUE ME DA ERROR:
clients = clientmethod.Add(clients);


}

public ArrayList getErrors(){
if (!hasErrors()){
errors = new ArrayList();
}
return errors;
}

public boolean hasErrors(){
return basicGetErrors()!=null;
}

private ArrayList basicGetErrors(){
return errors;
}

private Context getInitialContext() throws NamingException{
try{
//Get an InitialContext
return new InitialContext();
}
catch (NamingException ne){
log("We were unable to get a connection to the server with new InitialContext(). ");
log("Please make sure that the server is running.");
throw ne;
}
}
}

donde el clientsFacadeHome llama a un método del clientsFacade que es el siguiente:

public void Add (es.BBDDCaja.cajaelena.dto.clientsDto clientsdto)
throws java.rmi.RemoteException;

y ese método consiste en :

public void Add (clientsDto clientsdto)
{
clientsDao clientsdao = new clientsDao();
try
{
clientsdao.Create(clientsdto);
}
catch (SQLException e)
{
e.printStackTrace();
}
}

si me podéis ayudar os lo agradeceré. Un saludo

Elena