You are viewing a plain text version of this content. The canonical link for it is here.
Posted to httpclient-users@hc.apache.org by si...@bt.com on 2008/11/28 13:52:51 UTC

Facing problems to send viewstate value through post method

Hi,
I am trying to post data to one page through post method
It is working fine from IE
When I am trying to get the page from my java program by sending input
data the same page is coming but I am not getting the results page based
on the input.

When I examined the page there is one hiddenvalue '_viewstate' as that
page is developed by using JSF
>From the result page I am extracting the viewstate value and when post
all the input including viewstate I am getting  HTTP/1.1 405 Method Not
Allowed

Please guide me how to procede






Thanks and Regards, 
Sai, 
pp3.2.46, BT Ipswich ISU, Bibb Way, Ipswich, 
Suffolk, IP1 2EQ,UK 
+44 1473 348748 



Re: Facing problems to send viewstate value through post method

Posted by Chris Lowe <ch...@gmail.com>.
Sai,

I'll try to give a mini overview but I'm no expert myself.

When JSF produces a page it creates a structure of JSF components from your
jspx or facelets definition.  These components have state which may not
necessarily be obvious 'visible' data such as the component value, for
instance there may be properties used by the component implementation.

When you make a GET request for a page, then there is no previous state and
a new component heirarchy is generated.  When you post back to a JSF page,
the first thing JSF does is enter the RESTORE_VIEW phase where (I think) it
tries to access existing view state.  Without this, it cannot match the
inbound form values to components and, if I've got this right, this might be
causing you problems (esp. if you're relying on default component id
generation).

When storing view state, JSF generally has 2 modes (some implementations
bring other modes into the mix, but let's not complicate things): client
state management and server state management.  If you're using server mode,
then view state value you get in your hidden field will most likely be a
key/token that is used to retrieve view state that has been left somewhere
at the server.  If you're using client state saving mode, then the view
state value is Base64 encoded raw data of your page view state (and is
usually quite a lot of data!).  The view state can also be compressed and/or
encrypted prior to Base64 encoding depending on your JSF settings.

So if two identical forms are served then they *may* have the same client
view state (*if* your JSF implementation behaves like that, there's no
guarantee, and *if* no security features are turned on), but I think it's
unlikely they'd have the same server token.

By initially doing a get request you're ensuring that the view state,
regardless of whether it's stored at the client or server, is valid for your
post back.

Also check that the generated HTML for your form and input id attribute
values are not auto generated.  If this is the case, then you'll have more
work to do since you'll need to also extract and match up these.


I hope that helps, however I'd say that it's probably a good time to Google
on JSF and get an overview of the JSF application lifecycle and the state
saving modes ;)

Cheers,

Chris


2008/11/28 <si...@bt.com>

> Hi Chris,
> Thank you very much for that information.
> Here I need bit more clarification.
> If we parse the content resulting from GET Request and send it back will
> it be surely the same value? why because I was under the impression that
> it gets changed dynamically every time.
> And please also tell me what is viewstate will it be any string value or
> any certificate. I do not know any thing about JSF
>
>
> Thanks and Regards,
> Sai,
> pp3.2.46, BT Ipswich ISU, Bibb Way, Ipswich,
> Suffolk, IP1 2EQ,UK
> +44 1473 348748
>
>
> -----Original Message-----
> From: Chris Lowe [mailto:chris.lowe.uk@gmail.com]
> Sent: 28 November 2008 13:34
> To: HttpClient User Discussion
> Subject: Re: Facing problems to send viewstate value through post method
>
> Sai,
>
> It's not advisable to just copy the view state from your form - it will
> break the second you change your page structure.  Also, recent JSF 1.2
> implementations can be configured to expire view state as a security
> measure.
>
> Usually I do a GET request to the form URL first, parse the resulting
> content (a simple regex will suffice) in order to get viewstate value
> and then post back the form data with the view state.
>
> I hope that helps,
>
> Chris.
>
>
> 2008/11/28 <si...@bt.com>
>
> >
> > Hi,
> > I am trying to post data to one page through post method It is working
>
> > fine from IE When I am trying to get the page from my java program by
> > sending input data the same page is coming but I am not getting the
> > results page based on the input.
> >
> > When I examined the page there is one hiddenvalue '_viewstate' as that
>
> > page is developed by using JSF From the result page I am extracting
> > the viewstate value and when post all the input including viewstate I
> > am getting  HTTP/1.1 405 Method Not Allowed
> >
> > Please guide me how to procede
> >
> >
> >
> >
> >
> >
> > Thanks and Regards,
> > Sai,
> > pp3.2.46, BT Ipswich ISU, Bibb Way, Ipswich, Suffolk, IP1 2EQ,UK
> > +44 1473 348748
> >
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> For additional commands, e-mail: httpclient-users-help@hc.apache.org
>
>

Re: Facing problems to send viewstate value through post method

Posted by sebb <se...@gmail.com>.
Regardless of how JSF works internally, a browser only communicates
with a server using HTTP.

What you need to do is to ensure that the HttpClient code sends the
same (or sufficiently similar) requests as a browser would do.

In the case of form fields, when a user presses the send button, the
browser gathers up all the fields, which may be user specified or
hidden, and packages them as parameters of the HTTP request. Your code
needs to do the same.

See:

http://hc.apache.org/httpcomponents-client/primer.html

On 28/11/2008, sivasaibabu.parupalli@bt.com
<si...@bt.com> wrote:
> Hi Chris,
>  Thank you very much for that information.
>  Here I need bit more clarification.
>  If we parse the content resulting from GET Request and send it back will
>  it be surely the same value? why because I was under the impression that
>  it gets changed dynamically every time.
>  And please also tell me what is viewstate will it be any string value or
>  any certificate. I do not know any thing about JSF
>
>
>
>  Thanks and Regards,
>  Sai,
>  pp3.2.46, BT Ipswich ISU, Bibb Way, Ipswich,
>  Suffolk, IP1 2EQ,UK
>  +44 1473 348748
>
>
>
> -----Original Message-----
>  From: Chris Lowe [mailto:chris.lowe.uk@gmail.com]
>  Sent: 28 November 2008 13:34
>  To: HttpClient User Discussion
>  Subject: Re: Facing problems to send viewstate value through post method
>
>  Sai,
>
>  It's not advisable to just copy the view state from your form - it will
>  break the second you change your page structure.  Also, recent JSF 1.2
>  implementations can be configured to expire view state as a security
>  measure.
>
>  Usually I do a GET request to the form URL first, parse the resulting
>  content (a simple regex will suffice) in order to get viewstate value
>  and then post back the form data with the view state.
>
>  I hope that helps,
>
>  Chris.
>
>
>  2008/11/28 <si...@bt.com>
>
>  >
>  > Hi,
>  > I am trying to post data to one page through post method It is working
>
>  > fine from IE When I am trying to get the page from my java program by
>  > sending input data the same page is coming but I am not getting the
>  > results page based on the input.
>  >
>  > When I examined the page there is one hiddenvalue '_viewstate' as that
>
>  > page is developed by using JSF From the result page I am extracting
>  > the viewstate value and when post all the input including viewstate I
>  > am getting  HTTP/1.1 405 Method Not Allowed
>  >
>  > Please guide me how to procede
>  >
>  >
>  >
>  >
>  >
>  >
>  > Thanks and Regards,
>  > Sai,
>  > pp3.2.46, BT Ipswich ISU, Bibb Way, Ipswich, Suffolk, IP1 2EQ,UK
>  > +44 1473 348748
>  >
>  >
>  >
>
>
> ---------------------------------------------------------------------
>  To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
>  For additional commands, e-mail: httpclient-users-help@hc.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org


RE: Facing problems to send viewstate value through post method

Posted by si...@bt.com.
Hi Chris,
Thank you very much for that information.
Here I need bit more clarification.
If we parse the content resulting from GET Request and send it back will
it be surely the same value? why because I was under the impression that
it gets changed dynamically every time.
And please also tell me what is viewstate will it be any string value or
any certificate. I do not know any thing about JSF


Thanks and Regards, 
Sai, 
pp3.2.46, BT Ipswich ISU, Bibb Way, Ipswich, 
Suffolk, IP1 2EQ,UK 
+44 1473 348748 


-----Original Message-----
From: Chris Lowe [mailto:chris.lowe.uk@gmail.com] 
Sent: 28 November 2008 13:34
To: HttpClient User Discussion
Subject: Re: Facing problems to send viewstate value through post method

Sai,

It's not advisable to just copy the view state from your form - it will
break the second you change your page structure.  Also, recent JSF 1.2
implementations can be configured to expire view state as a security
measure.

Usually I do a GET request to the form URL first, parse the resulting
content (a simple regex will suffice) in order to get viewstate value
and then post back the form data with the view state.

I hope that helps,

Chris.


2008/11/28 <si...@bt.com>

>
> Hi,
> I am trying to post data to one page through post method It is working

> fine from IE When I am trying to get the page from my java program by 
> sending input data the same page is coming but I am not getting the 
> results page based on the input.
>
> When I examined the page there is one hiddenvalue '_viewstate' as that

> page is developed by using JSF From the result page I am extracting 
> the viewstate value and when post all the input including viewstate I 
> am getting  HTTP/1.1 405 Method Not Allowed
>
> Please guide me how to procede
>
>
>
>
>
>
> Thanks and Regards,
> Sai,
> pp3.2.46, BT Ipswich ISU, Bibb Way, Ipswich, Suffolk, IP1 2EQ,UK
> +44 1473 348748
>
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org


Re: Facing problems to send viewstate value through post method

Posted by Chris Lowe <ch...@gmail.com>.
Sai,

It's not advisable to just copy the view state from your form - it will
break the second you change your page structure.  Also, recent JSF 1.2
implementations can be configured to expire view state as a security
measure.

Usually I do a GET request to the form URL first, parse the resulting
content (a simple regex will suffice) in order to get viewstate value and
then post back the form data with the view state.

I hope that helps,

Chris.


2008/11/28 <si...@bt.com>

>
> Hi,
> I am trying to post data to one page through post method
> It is working fine from IE
> When I am trying to get the page from my java program by sending input
> data the same page is coming but I am not getting the results page based
> on the input.
>
> When I examined the page there is one hiddenvalue '_viewstate' as that
> page is developed by using JSF
> From the result page I am extracting the viewstate value and when post
> all the input including viewstate I am getting  HTTP/1.1 405 Method Not
> Allowed
>
> Please guide me how to procede
>
>
>
>
>
>
> Thanks and Regards,
> Sai,
> pp3.2.46, BT Ipswich ISU, Bibb Way, Ipswich,
> Suffolk, IP1 2EQ,UK
> +44 1473 348748
>
>
>