PDA

View Full Version : fileUpload: Unable to passing additional parameter on a submit (server side)



luisfernando.comp
15 Feb 2011, 6:11 PM
Hello,
Parameters are not being passed in the request when doing a form submit for a form that has a fileUpload: true.

In firebug, I see the values being past, but in my java event I can't access them.

Firebug:

Content-Type: multipart/form-data; boundary=---------------------------168072824752491622650073 Content-Length: 1300

-----------------------------168072824752491622650073 Content-Disposition: form-data; name="pathNFEntrada"; filename="teste.txt" Content-Type: text/plain

{\rtf1\ansi\ansicpg1252\cocoartf1038\cocoasubrtf350 {\fonttbl\f0\fswiss\fcharset0 Helvetica;} {\colortbl;\red255\green255\blue255;} \paperw11900\paperh16840\margl1440\margr1440\vieww9000\viewh8400\viewkind0 \pard\tx566\tx1133\tx1700\tx2267\tx2834\tx3401\tx3968\tx4535\tx5102\tx5669\tx6236\tx6803\ql\qnatural\pardirnatural

\f0\fs24 \cf0 teste}
-----------------------------168072824752491622650073 Content-Disposition: form-data; name="pathNFSaida"; filename="teste.txt" Content-Type: text/plain

{\rtf1\ansi\ansicpg1252\cocoartf1038\cocoasubrtf350 {\fonttbl\f0\fswiss\fcharset0 Helvetica;} {\colortbl;\red255\green255\blue255;} \paperw11900\paperh16840\margl1440\margr1440\vieww9000\viewh8400\viewkind0 \pard\tx566\tx1133\tx1700\tx2267\tx2834\tx3401\tx3968\tx4535\tx5102\tx5669\tx6236\tx6803\ql\qnatural\pardirnatural

\f0\fs24 \cf0 teste}
-----------------------------168072824752491622650073 Content-Disposition: form-data; name="dataInicio"

16/02/2011 -----------------------------168072824752491622650073 Content-Disposition: form-data; name="dataFim"

17/02/2011 -----------------------------168072824752491622650073--

Java code:


public static String importarArquivoSpedFiscal(HttpServletRequest request, HttpServletResponse response) throws Exception {

GenericDelegator delegator = (GenericDelegator) request.getAttribute("delegator");
Security security = (Security) request.getAttribute("security");
GenericValue userLogin = (GenericValue) request.getSession().getAttribute("userLogin");

String errorMessage = "error";

//################## Sped_Fiscal_0000 ###################
String dtIni = request.getParameter("dataFim");
String dtFim = request.getParameter("dataInicio");



dtIni and dtFim (which come from the formPanel) are always null.

Can anyone help me?

raj_plays
15 Feb 2011, 10:12 PM
Hi,
The parameters are being passed all right but on the server side they will have to be fetched from the form object in the request when fileUpload is set to true.
My server side code is in .Net and this is what I had to do...

HttpRequest request = HttpContext.Current.Request;
int id = request.Form["campaign_id"];


You can post your java code once you figure it out.

luisfernando.comp
16 Feb 2011, 9:41 AM
How to get additional parameters on a submit:

Java code:



public static String importarArquivoSpedFiscal(HttpServletRequest request, HttpServletResponse response) throws Exception {

//################## Sped_Fiscal_0000 ###################
String codigo_SF_0000 = null;
String organizationPartyId = null;
String indPerfil = null;
String indTipoAtividade = null;
Timestamp dataInicio = null;
Timestamp dataFim = null;
Timestamp periodoEntrega = null;;
String suframa = null;
String codFin = "0";

//################## Sped_Fiscal_0100 ###################
String codigo_SF_0100 = null;
String contador = null;
String crc = null;

//Classe utilizada para obtenção de dados vindos do submit de um form utilizando 'fileupload: true'
MultipartRequest req = new MultipartRequest(request, pathUploadFiles, "ISO-8859-1");
organizationPartyId = req.getParameter("organizationPartyId");
indPerfil = req.getParameter("indPerfil");
indTipoAtividade = req.getParameter("indTipoAtividade");
dataInicio = getData(req.getParameter("dataInicio"));
dataFim = getData(req.getParameter("dataFim"));
periodoEntrega = dataFim;
suframa = req.getParameter("suframa");
contador = req.getParameter("contador");
crc = req.getParameter("crc");

//more code here



I used the class MultipartRequest (download http://www.servlets.com/cos/index.html)

That's it.