to com problemas com upload de arquivo da maquina cliente para a maquina servidor…
na verdade eu nem queria salvar em nenhum diretorio no servidor…
to querendo usar um parser para ler um arquivo xml e descartá-lo.
adicionei a biblioteca no classpath do projeto, importei na classe, mas o erro insiste…
NoClassDefFoundError
sendo que a compila tranquilo
obtendo um objeto do tipo ‘File’ ta tudo pronto…
passei o request do jsp pra classe…
e a classe:
import java.util.Hashtable;
import javax.servlet.http.HttpServletRequest;
import javazoom.upload.MultipartFormDataRequest;
import javazoom.upload.UploadFile;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
public class RemessaXML {
public static OrcamentoXML[] lerOrcamentosXML(String arquivo, HttpServletRequest request) throws Exception {
OrcamentoXML[] orcamentos = new OrcamentoXML[0];
if (MultipartFormDataRequest.isMultipartFormData(request)){
// Uses MultipartFormDataRequest to parse the HTTP request.
MultipartFormDataRequest mrequest = new MultipartFormDataRequest(request);
String todo = mrequest.getParameter(arquivo);
if ( (todo != null) ){
Hashtable files = mrequest.getFiles();
if ( (files != null) || (!files.isEmpty()) )
{
UploadFile file = (UploadFile) files.get(arquivo);
System.out.println("<li>Form field : uploadfile"+"<BR> Uploaded file : "+file.getFileName()+" ("+file.getFileSize()+" bytes)"+"<BR> Content Type : "+file.getContentType());
// Uses the bean now to store specified by jsp:setProperty at the top.
//upBean.store(mrequest, "uploadfile");
// int lastid = ((DefaultDBStore)upBean.getDatabasestoreimplementation()).getLastId();
}
else
{
System.out.println("<li>No uploaded files");
}
}else{
System.out.println("<BR> todo="+todo);
}
}
//Vector history = upBean.getHistory();
//int amount = 0;
//if (history != null) amount = history.size();
/*
try{
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
File file = new File(arquivo);
Document doc = db.parse( file );
Element elem = doc.getDocumentElement();
// pega todos os elementos usuario do XML
NodeList nl = elem.getElementsByTagName( "ORCAMENTO" );
// prepara o vetor
orcamentos = new OrcamentoXML[nl.getLength()];
// percorre cada elemento usuario encontrado
for( int i=0; i<nl.getLength(); i++ ) {
Element tagOrcamento = (Element) nl.item( i );
// pega os dados cadastrado para o usuario atual
int id = Integer.parseInt( tagOrcamento.getAttribute( "ID" ) );
int vendedor = Integer.parseInt( getChildTagValue( tagOrcamento, "VENDEDOR") );
int empresa = Integer.parseInt( getChildTagValue( tagOrcamento, "EMPRESA") );
int origem = Integer.parseInt( getChildTagValue( tagOrcamento, "ORIGEM") );
int condicaoPgto = Integer.parseInt( getChildTagValue( tagOrcamento, "CONDICAOPGTO") );
int localCobranca = Integer.parseInt( getChildTagValue( tagOrcamento, "LOCALCOBRANCA") );
String emissao = getChildTagValue( tagOrcamento, "EMISSAO");
SimpleDateFormat form = new SimpleDateFormat("dd/MM/yyyy");
Date dataEmissao = form.parse(emissao);
int cliente = Integer.parseInt( getChildTagValue( tagOrcamento, "CLIENTE") );
ClienteNovo clienteNovo = null;
if(cliente==0){
NodeList nlClienteNovo = tagOrcamento.getElementsByTagName("CLIENTE_NOVO");
Element tagCliente = (Element) nlClienteNovo.item( 0 );
clienteNovo = new ClienteNovo(
getChildTagValue( tagCliente, "RAZAO"),
getChildTagValue( tagCliente, "NOME"),
getChildTagValue( tagCliente, "TIPOINSCRICAO"),
getChildTagValue( tagCliente, "CPFCNPJ"),
getChildTagValue( tagCliente, "RGIE"),
form.parse( getChildTagValue( tagCliente, "NASCIMENTO") ),
form.parse( getChildTagValue( tagCliente, "CADASTRO") ),
Integer.parseInt( getChildTagValue( tagCliente, "TIPOCLIENTE") ),
getChildTagValue( tagCliente, "REGIME"),
Integer.parseInt( getChildTagValue( tagCliente, "CEP") ),
Integer.parseInt( getChildTagValue( tagCliente, "CIDADE") ),
getChildTagValue( tagCliente, "ESTADO"),
getChildTagValue( tagCliente, "TIPOLOGRADOURO"),
getChildTagValue( tagCliente, "ENDERECO"),
getChildTagValue( tagCliente, "BAIRRO"),
getChildTagValue( tagCliente, "NUMERO"),
getChildTagValue( tagCliente, "REFERENCIA"),
getChildTagValue( tagCliente, "CONTATO"),
getChildTagValue( tagCliente, "SITE"),
getChildTagValue( tagCliente, "FONE1"),
getChildTagValue( tagCliente, "FONE2"),
getChildTagValue( tagCliente, "FAX"),
getChildTagValue( tagCliente, "OBSERVACAO")
);
}
String observacao = getChildTagValue( tagOrcamento, "OBS");
NodeList nlItens = tagOrcamento.getElementsByTagName("ITENS");
Element tagItens = (Element) nlItens.item( 0 );
NodeList nlItem = tagItens.getElementsByTagName("ITEM");
Item[] itens = new Item[nlItem.getLength()];
for( int a=0; a<nlItem.getLength(); a++ ) {
Element tagItem = (Element) nlItem.item( a );
int produto = Integer.parseInt( getChildTagValue( tagItem, "PRODUTO") );
int embalagem = Integer.parseInt( getChildTagValue( tagItem, "EMBALAGEM") );
double qtde = Double.parseDouble( getChildTagValue( tagItem, "QTDE") );
double valorUnit = Double.parseDouble( getChildTagValue( tagItem, "VALORUNIT") );
double valorDigit = Double.parseDouble( getChildTagValue( tagItem, "VALORDIGIT") );
double desconto = Double.parseDouble( getChildTagValue( tagItem, "DESCONTO") );
double total = Double.parseDouble( getChildTagValue( tagItem, "TOTAL") );
itens[a] = new Item(
produto,
embalagem,
qtde,
valorUnit,
valorDigit,
desconto,
total
);
}
// cria uma nova instancia do UsuarioGuj com os dados do xml
orcamentos[i] = new OrcamentoXML(
id,
vendedor,
empresa,
origem,
condicaoPgto,
localCobranca,
dataEmissao,
cliente,
clienteNovo,
observacao,
itens
);
// adiciona o usuario na coleção (vector) de usuários do guj
}
}catch (Exception e) {
e.printStackTrace();
orcamentos = new OrcamentoXML[0];
}
*/
return orcamentos;
}
// este método lê e retorna o conteúdo (texto) de uma tag (elemento)
// filho da tag informada como parâmetro. A tag filho a ser pesquisada
// é a tag informada pelo nome (string)
private static String getChildTagValue( Element elem, String tagName ) throws Exception {
NodeList children = elem.getElementsByTagName( tagName );
if( children == null ) return null;
Element child = (Element) children.item(0);
String saida = "";
try { saida = child.getFirstChild().getNodeValue(); }
catch (Exception e) { saida = ""; }
return saida;
}
}