Foros del Web » Programación para mayores de 30 ;) » Java »

GWT subir un archivo al servidor

Estas en el tema de GWT subir un archivo al servidor en el foro de Java en Foros del Web. Hola a todos! soy nuevo programando en GWT y me han mandado hacer un proyectillo que suba un archivo al servidor TOMCAT. Ando venga a ...
  #1 (permalink)  
Antiguo 02/07/2010, 01:46
 
Fecha de Ingreso: julio-2010
Mensajes: 1
Antigüedad: 13 años, 9 meses
Puntos: 0
GWT subir un archivo al servidor

Hola a todos!

soy nuevo programando en GWT y me han mandado hacer un proyectillo que suba un archivo al servidor TOMCAT. Ando venga a mirar ejemplos y todos me dan error. MI código es el siguiente.

public class FormPanelExample implements EntryPoint {

public void onModuleLoad() {
// Create a FormPanel and point it at a service.
final FormPanel form = new FormPanel();
form.setAction("/myFormHandler");

// Because we're going to add a FileUpload widget, we'll need to set the
// form to use the POST method, and multipart MIME encoding.
form.setEncoding(FormPanel.ENCODING_MULTIPART);
form.setMethod(FormPanel.METHOD_POST);

// Create a panel to hold all of the form widgets.
VerticalPanel panel = new VerticalPanel();
form.setWidget(panel);

// Create a TextBox, giving it a name so that it will be submitted.
final TextBox tb = new TextBox();
tb.setName("textBoxFormElement");
panel.add(tb);



// Create a FileUpload widget.
FileUpload upload = new FileUpload();
upload.setName("uploadFormElement");
panel.add(upload);

// Add a 'submit' button.
panel.add(new Button("Submit", new ClickListener() {
public void onClick(Widget sender) {
form.submit();
}
}));


FormHandler FH= new FormHandler(){
public void onSubmit(FormSubmitEvent event) {
// This event is fired just before the form is submitted. We can take
// this opportunity to perform validation.
if (tb.getText().length() == 0) {
Window.alert("The text box must not be empty");
event.setCancelled(true);
}
}

public void onSubmitComplete(FormSubmitCompleteEvent event) {
// When the form submission is successfully completed, this event is
// fired. Assuming the service returned a response of type text/html,
// we can get the result text here (see the FormPanel documentation for
// further explanation).
Window.alert(event.getResults());
}
};




form.addFormHandler(FH);




// Add an event handler to the form.
/* form.addFormHandler(new FormHandler() {
public void onSubmit(FormSubmitEvent event) {
// This event is fired just before the form is submitted. We can take
// this opportunity to perform validation.
if (tb.getText().length() == 0) {
Window.alert("The text box must not be empty");
event.setCancelled(true);
}
}

public void onSubmitComplete(FormSubmitCompleteEvent event) {
// When the form submission is successfully completed, this event is
// fired. Assuming the service returned a response of type text/html,
// we can get the result text here (see the FormPanel documentation for
// further explanation).
Window.alert(event.getResults());
}
});*/

RootPanel.get().add(form);
}
}


lo que el falta? alguna idea o tutorial para conseguir este objetivo???

Gracias y saludos a todos
  #2 (permalink)  
Antiguo 02/07/2010, 04:47
Avatar de dackiller  
Fecha de Ingreso: septiembre-2003
Ubicación: The Matrix
Mensajes: 341
Antigüedad: 20 años, 7 meses
Puntos: 4
Respuesta: GWT subir un archivo al servidor

Hola,

Segun lo que estoy viendo en tu codigo, solamente estas creando el formulario que va a enviar el archivo.


Debes manejar el archivo con un servlet que realmente esta en la ruta que especificastes aqui:

form.setAction("/myFormHandler");

Yo uso FileUpload de la fundacion apache para gestionar la subida de los archivos al servidor.

Recuerda que GWT es ajax, y ajax no puede gestionar la subida de los archivos.

Hace algun tiempo hice un componente GWT que al subir el archivo a un servlet especifico, este me creaba una barra de progreso con JSON indicandome el porcentaje subida del archivo. FileUpload de apache tiene la capacidad para monitorear la subida del archivo.

Saludos.
__________________
--
NOTA: Si haz conseguido la solución a tu problema, por favor edita el titulo del tema colocando el prefijo [SOLUCIONADO], para que otros usuarios puedan encontrar soluciones más rápido.

Etiquetas: gwt, subir, servidores
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 18:06.