You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Stéphane Arzt <sa...@i-d.net> on 2001/04/07 10:36:23 UTC

getting whole POSTed datas

Hello,

I really need help...
How may I get the whole POSTed datas from a form.
I tried to use request.parsePostData() but I don't know to do this.
May someone help me please ?

Thanks

Stef


---------------------------------------------------------------------
Please check that your question has not already been answered in the
FAQ before posting. <http://xml.apache.org/cocoon/faqs.html>

To unsubscribe, e-mail: <co...@xml.apache.org>
For additional commands, e-mail: <co...@xml.apache.org>


Re: getting whole POSTed datas

Posted by Matthew Cordes <mc...@maine.edu>.
Hi, 

perhaps try the reader interface, e.g.

	BufferedReader br = request.getReader();

	StringBuffer text = new StringBuffer();

	while ( br.ready() )
	{
		text.append( br.readLine() );
	}

// do something with text here...

Java's reader and writers are a very cool abstraction.  
Are you doing this from a servlet or cocoon?  I could be mistaken, 
but I was under the impression that from an xsp page certain things
(perhaps this) are protected from the user, although I could be mistaken.

-matt


On Mon, Apr 09, 2001 at 11:43:46AM +0200, St?phane Arzt wrote:
> OK, thanks rob,
> I opened a book and it doesn't work anymore :)
> there is my code :
> 
> .....
> int clength = request.getContentLength();
> String ctype = request.getContentType();
> ServletInputStream s = request.getInputStream();
> byte[] b = new byte[clength];
> int i = s.readLine(b, 0, clength);
> if(i != -1) {
>   String st = new String(b, 0, clength);
> }
> ......
> 
> It return me :
> content-Type : application/x-www-form-urlencoded
> content-Length : 18 (the real length of the request I posted)
> content : (nothing) because i always return me -1.
> 
> I can't see why if it knows content-length it can't return me the content of
> the request.
> 
> Please Help me !!
> 
> Sorry Viktor for my silly questions but it not easy to start ;)
> 
> Regards
> Stef
> 
> 
> 
> 
> Try request.getInputStream(); This will give you a servletinputstream from
> which you can read the raw data.
> 
> 
>   regards
> 
>   Rob

---------------------------------------------------------------------
Please check that your question has not already been answered in the
FAQ before posting. <http://xml.apache.org/cocoon/faqs.html>

To unsubscribe, e-mail: <co...@xml.apache.org>
For additional commands, e-mail: <co...@xml.apache.org>


RE: getting whole POSTed datas

Posted by Stéphane Arzt <sa...@i-d.net>.
OK, thanks rob,
I opened a book and it doesn't work anymore :)
there is my code :

.....
int clength = request.getContentLength();
String ctype = request.getContentType();
ServletInputStream s = request.getInputStream();
byte[] b = new byte[clength];
int i = s.readLine(b, 0, clength);
if(i != -1) {
  String st = new String(b, 0, clength);
}
......

It return me :
content-Type : application/x-www-form-urlencoded
content-Length : 18 (the real length of the request I posted)
content : (nothing) because i always return me -1.

I can't see why if it knows content-length it can't return me the content of
the request.

Please Help me !!

Sorry Viktor for my silly questions but it not easy to start ;)

Regards
Stef




Try request.getInputStream(); This will give you a servletinputstream from
which you can read the raw data.


  regards

  Rob

Re: getting whole POSTed datas

Posted by Gritsenko <vg...@acm.org>.
Read a chapter on Java Servlet API in any Java Serlet book, preferably O'Reily (look it up on Amazon.com).
There you will find the answers.

Questions you are asking are very basic, it's like asking hiw to drive a car on a maillist. Of course, you can continue to ask these, noone can prevent you from doing that, but that's what I think the nature of these questions is.

Viktor


----- Original Message ----- 
  From: Stéphane Arzt 
  To: cocoon-users@xml.apache.org 
  Sent: Sunday, April 08, 2001 12:23 PM
  Subject: RE: getting whole POSTed datas


   May you just tell me a little more please ??
   
  I done :
   
  ServletInputStream s = request.getInputStream();
  int clength = request.ContentLength();
  byte buff[] = null;
   
  s.readLine(buff, 0 clength);
   
  Now I have an array of byte..(I think ???), but when I do <xsp:expr>b</xsp:expr> It return me nothing....
  May you tell me where I make mistake please ?
   
  Thanks
   
  Stef
   
   
   Try request.getInputStream(); This will give you a servletinputstream from which you can read the raw data. 
   
       regards
     
    Rob
      ----- Original Message ----- 
      From: Stephane Arzt 
      To: cocoon-users@xml.apache.org 
      Sent: Sunday, April 08, 2001 9:29 PM
      Subject: RE: getting whole POSTed datas


      Thank you but I can't to do this because the datas I try to handle are in XML and are only values without a parameter.
      It's like page.xml?<login username="foo" password="bar"/> for the get method.
      For this reason I'd like to make something like getQueryString() but for the POST method.
      Is there a way to catch these datas directly from the header of the request ??

       

        Try to use this ;)

        getParameter
        public java.lang.String getParameter(java.lang.String name)
        Returns the value of a request parameter as a String, or null if the parameter does not exist. Request parameters are extra information sent with the request. 
        You should only use this method when you are sure the parameter has only one value. If the parameter might have more than one value, use getParameterValues(java.lang.String). 
        If you use this method with a multivalued parameter, the servlet engine determines the return value.
        Parameters: 
        name - a String specifying the name of the parameter 
        Returns: 
        a String representing the single value of the parameter




          Hello,

          I really need help...
          How may I get the whole POSTed datas from a form.
          I tried to use request.parsePostData() but I don't know to do this.
          May someone help me please ?

          Thanks

          Stef


          ---------------------------------------------------------------------
          Please check that your question has not already been answered in the
          FAQ before posting. <http://xml.apache.org/cocoon/faqs.html>

          To unsubscribe, e-mail: <co...@xml.apache.org>
          For additional commands, e-mail: <co...@xml.apache.org>
        Pozdrowienia,
        Oskar Werewka 


RE: getting whole POSTed datas

Posted by Stéphane Arzt <sa...@i-d.net>.
 May you just tell me a little more please ??

I done :

ServletInputStream s = request.getInputStream();
int clength = request.ContentLength();
byte buff[] = null;

s.readLine(buff, 0 clength);

Now I have an array of byte..(I think ???), but when I do
<xsp:expr>b</xsp:expr> It return me nothing....
May you tell me where I make mistake please ?

Thanks

Stef


 Try request.getInputStream(); This will give you a servletinputstream from
which you can read the raw data.

     regards

  Rob
    ----- Original Message -----
    From: Stephane Arzt
    To: cocoon-users@xml.apache.org
    Sent: Sunday, April 08, 2001 9:29 PM
    Subject: RE: getting whole POSTed datas


    Thank you but I can't to do this because the datas I try to handle are
in XML and are only values without a parameter.
    It's like page.xml?<login username="foo" password="bar"/> for the get
method.
    For this reason I'd like to make something like getQueryString() but for
the POST method.
    Is there a way to catch these datas directly from the header of the
request ??



      Try to use this ;)

      getParameter
      public java.lang.String getParameter(java.lang.String name)
      Returns the value of a request parameter as a String, or null if the
parameter does not exist. Request parameters are extra information sent with
the request.
      You should only use this method when you are sure the parameter has
only one value. If the parameter might have more than one value, use
getParameterValues(java.lang.String).
      If you use this method with a multivalued parameter, the servlet
engine determines the return value.
      Parameters:
      name - a String specifying the name of the parameter
      Returns:
      a String representing the single value of the parameter




        Hello,

        I really need help...
        How may I get the whole POSTed datas from a form.
        I tried to use request.parsePostData() but I don't know to do this.
        May someone help me please ?

        Thanks

        Stef


        --------------------------------------------------------------------
-
        Please check that your question has not already been answered in the
        FAQ before posting. <http://xml.apache.org/cocoon/faqs.html>

        To unsubscribe, e-mail: <co...@xml.apache.org>
        For additional commands, e-mail: <co...@xml.apache.org>
      Pozdrowienia,
      Oskar Werewka


Re: getting whole POSTed datas

Posted by Rob Parker <ro...@webcybernetics.com>.
Try request.getInputStream(); This will give you a servletinputstream from which you can read the raw data.

regards

Rob
  ----- Original Message ----- 
  From: Stephane Arzt 
  To: cocoon-users@xml.apache.org 
  Sent: Sunday, April 08, 2001 9:29 PM
  Subject: RE: getting whole POSTed datas


  Thank you but I can't to do this because the datas I try to handle are in XML and are only values without a parameter.
  It's like page.xml?<login username="foo" password="bar"/> for the get method.
  For this reason I'd like to make something like getQueryString() but for the POST method.
  Is there a way to catch these datas directly from the header of the request ??
   


    Try to use this ;)

    getParameter
    public java.lang.String getParameter(java.lang.String name)
    Returns the value of a request parameter as a String, or null if the parameter does not exist. Request parameters are extra information sent with the request. 
    You should only use this method when you are sure the parameter has only one value. If the parameter might have more than one value, use getParameterValues(java.lang.String). 
    If you use this method with a multivalued parameter, the servlet engine determines the return value.
    Parameters: 
    name - a String specifying the name of the parameter 
    Returns: 
    a String representing the single value of the parameter




      Hello,

      I really need help...
      How may I get the whole POSTed datas from a form.
      I tried to use request.parsePostData() but I don't know to do this.
      May someone help me please ?

      Thanks

      Stef


      ---------------------------------------------------------------------
      Please check that your question has not already been answered in the
      FAQ before posting. <http://xml.apache.org/cocoon/faqs.html>

      To unsubscribe, e-mail: <co...@xml.apache.org>
      For additional commands, e-mail: <co...@xml.apache.org>
    Pozdrowienia,
    Oskar Werewka 


RE: getting whole POSTed datas

Posted by Stephane Arzt <sa...@i-d.net>.
Thank you but I can't to do this because the datas I try to handle are in
XML and are only values without a parameter.
It's like page.xml?<login username="foo" password="bar"/> for the get
method.
For this reason I'd like to make something like getQueryString() but for the
POST method.
Is there a way to catch these datas directly from the header of the request
??



  Try to use this ;)

  getParameter
  public java.lang.String getParameter(java.lang.String name)
  Returns the value of a request parameter as a String, or null if the
parameter does not exist. Request parameters are extra information sent with
the request.
  You should only use this method when you are sure the parameter has only
one value. If the parameter might have more than one value, use
getParameterValues(java.lang.String).
  If you use this method with a multivalued parameter, the servlet engine
determines the return value.
  Parameters:
  name - a String specifying the name of the parameter
  Returns:
  a String representing the single value of the parameter




    Hello,

    I really need help...
    How may I get the whole POSTed datas from a form.
    I tried to use request.parsePostData() but I don't know to do this.
    May someone help me please ?

    Thanks

    Stef


    ---------------------------------------------------------------------
    Please check that your question has not already been answered in the
    FAQ before posting. <http://xml.apache.org/cocoon/faqs.html>

    To unsubscribe, e-mail: <co...@xml.apache.org>
    For additional commands, e-mail: <co...@xml.apache.org>
  Pozdrowienia,
  Oskar Werewka


Re: getting whole POSTed datas

Posted by David Holsclaw <ho...@mac.com>.
I have a related question...

What if you are doing this dynamically and don't know all of the 
parameter names? Is there a way to get an enumeration of all the 
parameters and iterate over that? I have tried using HttpRequest in an 
xsp:logic section to get this but have had no luck trying to use 
anything from javax.servlet from within C2. I also looked through the 
xsp-request logicsheet and its helper class but can't find a way to do 
this.

Any suggestions would be greatly appreciated.

Note: I am using Cocoon2 with Tomcat4b3 on Mac OS X.

Thanks.
---
David Holsclaw
dholsclaw@mac.com


---------------------------------------------------------------------
Please check that your question has not already been answered in the
FAQ before posting. <http://xml.apache.org/cocoon/faqs.html>

To unsubscribe, e-mail: <co...@xml.apache.org>
For additional commands, e-mail: <co...@xml.apache.org>


Re: getting whole POSTed datas

Posted by Oskar Werewka <ow...@priv4.onet.pl>.
Try to use this ;)

getParameter
public java.lang.String getParameter(java.lang.String name)
Returns the value of a request parameter as a String, or null if the 
parameter does not exist. Request parameters are extra information sent 
with the request.
You should only use this method when you are sure the parameter has only 
one value. If the parameter might have more than one value, use 
getParameterValues(java.lang.String).
If you use this method with a multivalued parameter, the servlet engine 
determines the return value.
Parameters:
name - a String specifying the name of the parameter
Returns:
a String representing the single value of the parameter



>Hello,
>
>I really need help...
>How may I get the whole POSTed datas from a form.
>I tried to use request.parsePostData() but I don't know to do this.
>May someone help me please ?
>
>Thanks
>
>Stef
>
>
>---------------------------------------------------------------------
>Please check that your question has not already been answered in the
>FAQ before posting. <http://xml.apache.org/cocoon/faqs.html>
>
>To unsubscribe, e-mail: <co...@xml.apache.org>
>For additional commands, e-mail: <co...@xml.apache.org>

Pozdrowienia,
Oskar Werewka