It redirects but shows the jsp source code.
Quintin Beukes-2 wrote:
>
> Does it not redirect?
>
> Or does it show the JSP source code?
>
>
> On 6/24/08, raju <[EMAIL PROTECTED]> wrote:
>>
>> Hi Quintin ,
>>
>> I am basically Logging in by passing login credentials.On successful
>> login
>> user is taken to a jsp which lists say list of employees from database.I
>> am
>> ending up getting the jsp code in response not the one which contains
>> ids(dynamic data from DB) data displayed.If i do view source from
>> browser i
>> can see links for various ids.
>>
>>
>> Heres the code if uploaded one was not available.
>> ---------------------------------------------------
>>
>>
>> import java.io.IOException;
>>
>> import org.apache.commons.httpclient.Cookie;
>> import org.apache.commons.httpclient.DefaultHttpMethodRetryHandler;
>> import org.apache.commons.httpclient.HttpClient;
>> import org.apache.commons.httpclient.HttpException;
>> import org.apache.commons.httpclient.NameValuePair;
>> import org.apache.commons.httpclient.cookie.CookiePolicy;
>> import org.apache.commons.httpclient.methods.GetMethod;
>> import org.apache.commons.httpclient.methods.PostMethod;
>> import org.apache.commons.httpclient.params.HttpMethodParams;
>>
>>
>> public class RedirectHttpClient {
>>
>> static String LOGON_SITE = "";
>>
>> static int LOGON_PORT = 0;
>>
>> static String LOGON_PROTOCOL = "";
>>
>> public RedirectHttpClient() {
>> super();
>> }
>>
>> /**
>> * @param args
>> */
>> public static void main(String[] args) {
>> // TODO Auto-generated method stub
>> getWebPage();
>> }
>>
>>
>>
>> public static void getWebPage() {
>> String urlDetails[] = splitURL("https://mysite.com");
>> LOGON_PROTOCOL = urlDetails[0];
>> LOGON_SITE = urlDetails[1];
>>
>> if (urlDetails.length != 2) {
>>
>> LOGON_PORT = Integer.parseInt(urlDetails[2].trim());
>> }
>> String url = "https://mysite.com/servlets/Logon";
>> HttpClient client = new HttpClient();
>> client.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
>> new DefaultHttpMethodRetryHandler(0, false));
>>
>> client.getHostConfiguration().setHost(LOGON_SITE, LOGON_PORT,
>> LOGON_PROTOCOL);
>>
>> GetMethod get = new GetMethod(url);
>> NameValuePair[] data = new NameValuePair[2];
>> data[0] = new NameValuePair("username", "xyz");
>> data[1] = new NameValuePair("password", "xyz");
>> get.setQueryString(data);
>> get.setFollowRedirects(true);
>>
>> String strGetResponseBody = null;
>>
>> try {
>> int iGetResultCode = client.executeMethod(get);
>> System.out.println(get.getURI());
>>
>>
>> strGetResponseBody = get.getResponseBodyAsString();
>> // System.out.println(strGetResponseBody);
>> System.out.println(get.getRequestHeader("Cookie"));
>> Cookie[] cookies = client.getState().getCookies();
>> for (int i = 0; i < cookies.length; i++) {
>> System.out.println("lets check if its coming here");
>> Cookie cookie = cookies[i];
>> System.out.println("Cookie: " + cookie.getName() + ",
>> Value:
>> " + cookie.getValue()
>> + ", IsPersistent?: " + cookie.isPersistent() + ",
>> Expiry Date: "
>> + cookie.getExpiryDate() + ", Comment: " +
>> cookie.getComment());
>>
>> cookie.setValue("My own value");
>> }
>>
>> PostMethod authget = new
>> PostMethod("https://mysite.com/html/details.jsp");
>> authget.setRequestHeader(get.getRequestHeader("Cookie"));
>> authget.setRequestHeader(get.getRequestHeader("Host"));
>> authget.setRequestHeader(get.getRequestHeader("User-Agent"));
>>
>> client.executeMethod(authget);
>> String responseBody1 = authget.getResponseBodyAsString();
>>
>> } catch (Exception ex) {
>> ex.printStackTrace();
>> } finally {
>> get.releaseConnection();
>> }
>> }
>>
>> /**
>> * Splits url into protocol,host and port.
>> *
>> * @param url
>> * @return
>> */
>> private static String[] splitURL(String url) {
>> String[] ulrDetails = null;
>> String urlStr = url.replace("//", "");
>> String regex = ":";
>>
>>
>> ulrDetails = urlStr.split(regex);
>>
>> return ulrDetails;
>> }
>> }
>> Thanks
>> Raj
>>
>>
>>
>>
>>
>>
>>
>> Quintin Beukes-2 wrote:
>> >
>> > Hey,
>> >
>> > Can you please explain in more detail what you are trying to achieve,
>> > and what the results are?
>> >
>> > Q
>> >
>> > On 6/24/08, raju <[EMAIL PROTECTED]> wrote:
>> >>
>> >> Hi,
>> >>
>> >> I am able to redirect on successful Login to a jsp page which lists
>> >> data.But i still seem to get the jsp content not along with the
>> >> dynamically
>> >> generated data as the response.Maybe i may have to submit to jsp
>> again
>> >> which
>> >> i tried.
>> >>
>> >> Code for same is attached.
>> >>
>> >> Regards
>> >> Raj
>> >>
>> >> --
>> >> View this message in context:
>> >>
>> http://www.nabble.com/Redirect....Posting-data-to-a-jsp-and-Reading-html-response-from-it...-tp18090021p18090021.html
>> >> Sent from the HttpClient-User mailing list archive at Nabble.com.
>> >>
>> >>
>> >>
>> ---------------------------------------------------------------------
>> >> To unsubscribe, e-mail: [EMAIL PROTECTED]
>> >> For additional commands, e-mail: [EMAIL PROTECTED]
>> >>
>> >>
>> >
>> >
>> >
>> > --
>> > Quintin Beukes
>> >
>> > ---------------------------------------------------------------------
>> > To unsubscribe, e-mail: [EMAIL PROTECTED]
>> > For additional commands, e-mail: [EMAIL PROTECTED]
>> >
>> >
>> >
>>
>> --
>>
>> View this message in context:
>> http://www.nabble.com/Redirect....Posting-data-to-a-jsp-and-Reading-html-response-from-it...-tp18090021p18091092.html
>>
>> Sent from the HttpClient-User mailing list archive at Nabble.com.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [EMAIL PROTECTED]
>> For additional commands, e-mail: [EMAIL PROTECTED]
>>
>>
>
>
> --
> Quintin Beukes
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
>
--
View this message in context:
http://www.nabble.com/Redirect....Posting-data-to-a-jsp-and-Reading-html-response-from-it...-tp18090021p18104911.html
Sent from the HttpClient-User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]