On Thu, 18 Jul 2002, Luca Ventura wrote: > Hello! > > I tried to do it but the getParameterNames() method seems not to > detect the hidden input field without a name !!! In fact using the > getParameterNames() method I obtain all the parameters except those > without a name....this is the problem! :-(
Well, there are other getParameter* methods on the request, but I'm not sure any of them will be useful, since I think they all rely on having some "key" (i.e. the parameter name) to extract the relevant parameter value. You might have to use a lower level technique, like parsing the query string yourself (perhaps making use of getQueryString). But you might also step back and ask why you're doing this, what you're trying to do. Looking back at your original note (still appended below), you say you've seen hidden parameters used with a value but without a name, but without knowing how they are used and what for. First, you might check into that further. I don't even know if such things are covered by the HTTP spec (let alone how different implementations handle it). And as to the code example you gave, it looks like you're just trying to save having to check for null/empty names/values -- that should be easy to fix, and you can always insert dummy names/values if something is missing. In sum, it might be better to clarify exactly what you're trying to do and why (to yourself and/or the list). > -----Messaggio originale----- > Da: A mailing list for discussion about Sun Microsystem's Java Servlet > API Technology. [mailto:[EMAIL PROTECTED]]Per conto di > RBonazzo > Inviato: gioved� 18 luglio 2002 17.23 > A: [EMAIL PROTECTED] > Oggetto: R: Input hidden fields without name > Priorit�: Alta > > > Hi Luca, > Why don't you try to create a form with this type of input field, send > it to a servlet and look the contain of the list of parameters you > receive in this case. > Use getParameterNames() > > Regards > Rinaldo > > > -----Messaggio originale----- > Da: A mailing list for discussion about Sun Microsystem's Java Servlet > API Technology. [mailto:[EMAIL PROTECTED]] Per conto di Luca > Ventura > Inviato: gioved� 18 luglio 2002 16.27 > A: [EMAIL PROTECTED] > Oggetto: Input hidden fields without name > > > Hello everybody! > > Surfing in Internet I have seen that some html forms use input hidden > fields without name, like this: > > <input type=hidden value=""> > > It is very strange....what are they useful for??? :-( > > Anyway I would like to get in my Java servlets such type of parameters > but I don't know how to do because the getParameterNames() method of > HttpServletRequest object needs that the input field has a name to get > its value! > > Then I would ike to simulate an html form and I would like to be able to > send parameter without name (see above) to another servlet (called > "ServletB"): how can I do? > > To encode the parameters to send and their values I use this Java code: > > . > > String > ParamHtml=ParamName1+"="+URLEncoder.encode(ValueParam1)+"&"+ParamName2+U > RLEn > coder.encode(ValueParam2)+...; > HttpURLConnection Con = (HttpURLConnection)url.openConnection(); > Con.setRequestMethod("POST"); > Con.setDoOutput(true); > Con.setUseCaches(false); > Con.setRequestProperty("Content-Length",""+ParamHtml.length()); > Con.setRequestProperty("Content-Type","application/x-www-form-urlencoded > "); > ByteArrayOutputStream byteStream=new ByteArrayOutputStream(512); > PrintWriter out=new PrintWriter(byteStream,true); out.print(ParamHtml); > out.flush(); OutputStream Os=Con.getOutputStream(); > byteStream.writeTo(Os); > > . > > In this case if ParamName1 is a parameter without name and without value > (<input type=hidden value="">)ParamNameHtml should have the following > value: > > =&ParamName2+URLEncoder.encode(ValueParam2)+...; > > Is it so? I tried to codify it in this way but when ServletB receives > the parameters it isn't able to read them because the syntax seems to be > wrong....:-( [ ... ] Milt Epstein Research Programmer Systems and Technology Services (STS) Campus Information Technologies and Educational Services (CITES) University of Illinois at Urbana-Champaign (UIUC) [EMAIL PROTECTED] ___________________________________________________________________________ To unsubscribe, send email to [EMAIL PROTECTED] and include in the body of the message "signoff SERVLET-INTEREST". Archives: http://archives.java.sun.com/archives/servlet-interest.html Resources: http://java.sun.com/products/servlet/external-resources.html LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
