IgorCicompuitPJ 27 de dez. de 2006
Segue o código até o momento.
& lt ; ! DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd" & gt ;
& lt ; struts & gt ;
& lt ; package name = "fileupload" extends = "principal" & gt ;
& lt ; action name = "fileuploadenviar" class = "com.struts.FileUploadAction" method = "enviar" & gt ;
& lt ; interceptor - ref name = "fileUpload" /& gt ;
& lt ; interceptor - ref name = "defaultStack" /& gt ;
& lt ; result name = "success" & gt ; / index . jsp & lt ; / result & gt ;
& lt ; result name = "fails" & gt ; / index . jsp & lt ; / result & gt ;
& lt ; / action & gt ;
& lt ; / package & gt ;
& lt ; include file = "struts-default.xml" /& gt ;
& lt ; / struts & gt ;
& lt ; ! DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd" & gt ;
& lt ; struts & gt ;
& lt ; package name = "principal" extends = "struts-default" & gt ;
& lt ; interceptors & gt ;
& lt ; interceptor name = "hibernate" class = "com.struts.HibernateOpenSessionInViewInterceptor" /& gt ;
& lt ; interceptor - stack name = "stackGeral" & gt ;
& lt ; interceptor - ref name = "hibernate" /& gt ;
& lt ; interceptor - ref name = "fileUpload" /& gt ;
& lt ; interceptor - ref name = "defaultStack" /& gt ;
& lt ; / interceptor - stack & gt ;
& lt ; / interceptors & gt ;
& lt ; default - interceptor - ref name = "stackGeral" /& gt ;
& lt ; global - results & gt ;
& lt ; result name = "login" type = "redirect" & gt ; / monitoramento . jsp & lt ; / result & gt ;
& lt ; result name = "error" type = "redirect" & gt ; / pages / Erro . jsp & lt ; / result & gt ;
& lt ; / global - results & gt ;
& lt ; action name = "principal" class = "com.struts.GenericAction" & gt ;
& lt ; result name = "success" & gt ; / META - INF / pages / principal . jsp & lt ; / result & gt ;
& lt ; / action & gt ;
& lt ; / package & gt ;
& lt ; include file = "struts-default.xml" /& gt ;
& lt ; include file = "faleconosco.xml" /& gt ;
& lt ; include file = "fileupload.xml" /& gt ;
& lt ; / struts & gt ;
& lt ; % @ taglib uri = "/struts-tags" prefix = "s" %& gt ;
& lt ; jsp & #58;include page="/layouts/cabecalho.jsp"/>
& lt ; table width = "70%" height = "508" border = "0" align = "center" cellpadding = "0" cellspacing = "10" & gt ;
& lt ; tr & gt ;
& lt ; td height = "2" align = "center" & gt ; & lt ; img src = "img/px1_azul.jpg" width = "100%" height = "1" & gt ; & lt ; / td & gt ;
& lt ; / tr & gt ;
& lt ; tr & gt ;
& lt ; td height = "410" valign = "top" align = "center" & gt ;
& lt ; table border = "0" cellpadding = "2" cellspacing = "2" width = "391" align = "center" & gt ;
& lt ; form action = "fileuploadenviar.action" method = "post" enctype = "multipart/form-data" & gt ;
& lt ; tr valign = "middle" & gt ;
& lt ; td align = "right" & gt ; Descricao & #58;</td>
& lt ; td & gt ; & lt ; input type = "text" name = "descricao" label = "descricao" class = "form" & gt ; & lt ; / td & gt ;
& lt ; / tr & gt ;
& lt ; tr valign = "middle" & gt ;
& lt ; td align = "right" & gt ; Arquivo & #58;</td>
& lt ; td & gt ; & lt ; input type = "file" name = "upload" label = "File" & gt ; & lt ; / td & gt ;
& lt ; / tr & gt ;
& lt ; tr valign = "middle" & gt ;
& lt ; td align = "right" & gt ; & lt ; / td & gt ;
& lt ; td & gt ; & lt ; input class = "button" type = "submit" value = "Enviar" & gt ; & lt ; / td & gt ;
& lt ; / tr & gt ;
& lt ; / form & gt ;
& lt ; / table & gt ;
& lt ; / td & gt ;
& lt ; / tr & gt ;
& lt ; / table & gt ;
& lt ; jsp & #58;include page="/layouts/rodape.jsp"/>
/*
* FileUploadAction.java
*
* Created on 8 de Dezembro de 2006, 16:13
*
*/
package com.struts ;
import java.io.File ;
import org.apache.struts2.Action ;
public class FileUploadAction implements Action & # 123 ;
private File upload ;
private String uploadContentType ;
private String uploadFileName ;
public String enviar & # 40 ; & # 41 ; & # 123 ;
return "success" ;
& # 125 ;
public String execute & # 40 ; & # 41 ; & # 123 ;
String retorno = "fails" ;
if & # 40 ; upload == null & # 41 ; & # 123 ;
retorno = "success" ;
& # 125 ;
return retorno ;
& # 125 ;
public File getUpload & # 40 ; & # 41 ; & # 123 ;
return upload ;
& # 125 ;
public void setUpload & # 40 ; File upload & # 41 ; & # 123 ;
this . upload = upload ;
& # 125 ;
public String getUploadContentType & # 40 ; & # 41 ; & # 123 ;
return uploadContentType ;
& # 125 ;
public void setUploadContentType & # 40 ; String uploadContentType & # 41 ; & # 123 ;
this . uploadContentType = uploadContentType ;
& # 125 ;
public String getUploadFileName & # 40 ; & # 41 ; & # 123 ;
return uploadFileName ;
& # 125 ;
public void setUploadFileName & # 40 ; String uploadFileName & # 41 ; & # 123 ;
this . uploadFileName = uploadFileName ;
& # 125 ;
& # 125 ;