How to Login in a JSF page using java -


i'm trying login in .jsf intranet page, here part of it:

     <form method="post" action="j_security_check" name="loginform" id="loginform">                 <input name="j_username" type="text" class="textbox" maxlength="30"/>                 <input name="j_password" type="password" class="textbox" maxlength="30"/>                 <input type=submit value="enter" class="button">                 <input type=submit value="exit" class="button">     </form> 

i've searched , tryied @ java, didn't worked, same page result:

            httppost post = new httppost("http://xxxx/login.jsf");                 list <namevaluepair> parameters = new arraylist <namevaluepair>();                parameters.add(new basicnamevaluepair("j_username", "92232776"));                parameters.add(new basicnamevaluepair("j_password", "(7110oi14)"));               urlencodedformentity sendentity;              sendentity = new urlencodedformentity(parameters, http.utf_8);              post.setentity(sendentity);                 httpclient client = new defaulthttpclient();                httpresponse response = client.execute(post, httpcontext);                 system.out.print(convertinputstreamtostring(response.getentity().getcontent()));    

(i'm using httpcomponents-client-4.2)

what need login in page? there need code button "send"?

thank guys.

the login information stored in session. session backed cookies. need maintain cookies across requests. basically, need pass retrieved set-cookie response header on every subsequent http request in same session long cookie valid.

in httpclient, need prepare cookiestore set in httpcontext in turn pass on every httpclient#execute() call.

httpclient httpclient = new defaulthttpclient(); cookiestore cookiestore = new basiccookiestore(); httpcontext httpcontext = new basichttpcontext(); httpcontext.setattribute(clientcontext.cookie_store, cookiestore); // ...  httpresponse response1 = httpclient.execute(method1, httpcontext); // ...  httpresponse response2 = httpclient.execute(method2, httpcontext); // ... 

please note j_security_check login step not related jsf, applies every other java servlet based login form well. once intend submit real jsf form created <h:form>, you'd need take lot more account. head more detailed answer then: how can programmatically upload file website? whilst treats uploading of file programmatically through jsf form, basic principles submitting jsf form same (certain hidden input fields have taken account , on).


Comments

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c++ - Using OpenSSL in a multi-threaded application -

All overlapping substrings matching a java regex -