JSP and JSTL Tutorials - Tutorial Addendum - JSP Sessions and Debugging

arcadegamesios wordgamesios lifestyleappsios
 31 December 18:00   

    



    



    

(Continued from antecedent part...)

    



    

Here is my sample new s/computers-and-technology/perl-list/' onMouseOver="tip('infobox1')" onMouseOut="untip()"> Perl program, reg_client.pl, advised to plan with my antecedent

    

JSP allotment application:

    

 

    

#- reg_client.pl

    

#- Absorb (c) 2002 by Dr. Yang

    

use LWP::Debug qw(+);

    

use LWP::UserAgent;

    

use HTTP::Cookies;

    

($url) = @ARGV;

    

$url = http://localhost unless $url;

    

$ua = new LWP::UserAgent;

    

$cookie_jar = HTTP::Cookies-> new ;

    

&getForm();

    

&submitForm();

    

exit;

    

sub getForm {

    

$u = $url. /RegForm.jsp ;

    

my $req = new HTTP::Request GET => $u;

    

my $res = $ua->request($req);

    

$req = $res->request();

    

$cookie_jar->extract_cookies($res);

    

&dump($req,$res);

    

}

    

sub submitForm {

    

$u = $url. /RegForm.jsp?name=Mike&pass=None&color=Blue&submit=Submit ;

    

my $req = new HTTP::Request GET => $u;

    

$cookie_jar->add_cookie_header($req);

    

my $res = $ua->request($req);

    

$req = $res->request();

    

$cookie_jar->extract_cookies($res);

    

&dump($req,$res);

    

}

    

sub dump {

    

bounded ($req,$res) = @_;

    

book "
REQUEST-HEADERS
";

    

book $req->headers_as_string();

    

book "
REQUEST-CONTENT
";

    

book $req->content;

    

if ($res->is_success) {

    

book "
RESPONSE-HEADERS
";

    

book $res->headers_as_string();

    

book "
RESPONSE-CONTENT
";

    

book $res->content;

    

} abroad {

    

book "
RESPONSE-ERROR
";

    

book $res->error_as_HTML();

    

}

    

}

    



    



    

A brace of addendum to advice you to accept this program:

    



        

  • "use LWP::Debug qw(+);" turns on the debugging at the accomplished level.

        



  •     

  • A "LWP::UserAgent" item is acclimated to forward a HTTP appeal to the HTTP server.

        



  •     

  • "HTTP:Request" altar are acclimated to compose HTTP requests.

        



  •     

  • "$cookie_jar->extract_cookies($res);" is acclimated to abstract accolade from the

        

    response. This is actual important, because JSP server is sending the affair ID

        

    as a cookie to the applicant and assured the applicant to forward it aback in the next

        

    request.

        



  •     

  • "$cookie_jar->add_cookie_header($req);" is acclimated to add the accolade received

        

    from the antecedent acknowledgment to the accepted request. One of the accolade is the

        

    session id, which is important for the JSP server to admit the accepted request

        

    is a assiduity of the antecedent request.

        



  •     



    



    

If you run it with "reg_client.pl http://localhost:8080 > client.out" in

    

a command window, you will get the afterward in the window:

    

 

    

LWP::UserAgent:: new : ()

    

LWP::UserAgent::request: ()

    

LWP::UserAgent::simple_request: GET http://localhost:8080/RegForm.jsp

    

LWP::UserAgent::_need_proxy: Not proxied

    

LWP::Protocol::http::request: ()

    

LWP::Protocol::http::request: GET /RegForm.jsp HTTP/1.0

    

Host: localhost:8080

    

User-Agent: libwww-perl/5.51

    

LWP::Protocol::http::request: account response

    

LWP::Protocol::http::request: HTTP/1.1 200 OK

    

Set-Cookie: JSESSIONID=887896C93DFFF372EB38818BF9F68DB2; Path=/

    

Content-Type: text/html;charset=UTF-8

    

Content-Length: 393

    

Date: Sat, 28 Dec 2002 20:37:04 GMT

    

Server: Apache Coyote/1.0

    

Connection: close

    

<html><body><b>Registration Form</b>:<br/><form action=RegForm.jsp met

    

hod=get>Login Name:<input type=text size=16 name=name><br/>Password:<i

    

nput type=text size=16 name=pass><br/>Favor Color:<input type=text siz

    

e=16 name=color><br/><input type=submit name=submit value=Submit></br>

    

</form>Your affair ID is 887896C93DFFF372EB38818BF9F68DB2<br/>Last us

    

er on the server: Nobody<br/></body></html>

    

LWP::Protocol::http::request: HTTP/1.1 200 OK

    

LWP::Protocol::collect: apprehend 393 bytes

    

LWP::UserAgent::request: Simple response: OK

    

HTTP::Cookies::extract_cookies: Set cookie JSESSIONID => 887896C93DFFF

    

372EB38818BF9F68DB2

    

HTTP::Cookies::add_cookie_header: Blockage localhost.local for cookies

    

HTTP::Cookies::add_cookie_header: - blockage cookie path=/

    

HTTP::Cookies::add_cookie_header: - blockage cookie JSESSIONID=887896

    

C93DFFF372EB38818BF9F68DB2

    

HTTP::Cookies::add_cookie_header: it s a match

    

HTTP::Cookies::add_cookie_header: Blockage .local for cookies

    

LWP::UserAgent::request: ()

    

LWP::UserAgent::simple_request: GET http://localhost:8080/RegForm.jsp?

    

name=Mike&pass=None&color=Blue&submit=Submit

    

LWP::UserAgent::_need_proxy: Not proxied

    

LWP::Protocol::http::request: ()

    

LWP::Protocol::http::request: GET /RegForm.jsp?name=Mike&pass=None&col

    

or=Blue&submit=Submit HTTP/1.0

    

Host: localhost:8080

    

User-Agent: libwww-perl/5.51

    

Cookie: JSESSIONID=887896C93DFFF372EB38818BF9F68DB2

    

Cookie2: $Version=1

    

LWP::Protocol::http::request: account response

    

LWP::Protocol::http::request: HTTP/1.1 302 Confused Temporarily

    

Location: http://localhost:8080/RegDone.jsp?color=Blue

    

Content-Type: text/html;charset=UTF-8

    

Content-Length: 0

    

Date: Sat, 28 Dec 2002 20:37:04 GMT

    

Server: Apache Coyote/1.0

    

Connection: close

    

LWP::Protocol::http::request: HTTP/1.1 302 Confused Temporarily

    

LWP::UserAgent::request: Simple response: Found

    

LWP::UserAgent::request: ()

    

LWP::UserAgent::simple_request: GET http://localhost:8080/RegDone.jsp?

    

color=Blue

    

LWP::UserAgent::_need_proxy: Not proxied

    

LWP::Protocol::http::request: ()

    

LWP::Protocol::http::request: GET /RegDone.jsp?color=Blue HTTP/1.0

    

Host: localhost:8080

    

User-Agent: libwww-perl/5.51

    

Cookie: JSESSIONID=887896C93DFFF372EB38818BF9F68DB2

    

Cookie2: $Version=1

    

LWP::Protocol::http::request: account response

    

LWP::Protocol::http::request: HTTP/1.1 200 OK

    

Content-Type: text/html

    

Content-Length: 221

    

Date: Sat, 28 Dec 2002 20:37:04 GMT

    

Server: Apache Coyote/1.0

    

Connection: close

    

LWP::Protocol::http::request: HTTP/1.1 200 OK

    

LWP::Protocol::collect: apprehend 221 bytes

    

LWP::UserAgent::request: Simple response: OK

    



    



    

We accept a lot of advice here. Let s assay it quickly.

    



        

  • My first appeal was beatific as "GET /RegForm.jsp HTTP/1.0".

        



  •     

  • The first acknowledgment came aback with a cookie as: "JSESSIONID=887896C93DFFF372EB38818BF9F68DB2".

        

    Apparently, this is the affair ID, but encrypted.

        



  •     

  • My additional appeal was beatific as "GET /RegForm.jsp?name=Mike... HTTP/1.0",

        

    with two cookies. The first cookie was the JSP server affair ID. The additional cookie

        

    came from nowhere.

        



  •     

  • The additional acknowledgment was interesting. It had cipher of "302 Confused Temporarily", and a

        

    "Location" attack band advertence the new URL. Obviously, this acknowledgment was generated by the

        

    "sendRedirect()" action in my JSP page, RegForm.jsp.

        



  •     

  • The LWP::UserAgent item is smart. It accustomed the "302 Confused Temporarily" code, and

        

    automatically forward addition appeal with new URL location.

        



  •     

  • With no surprises, the third acknowledgment came ok. The JSP did admit my session

        

    ID in my additional and third request. But acknowledgment agreeable was missing in the debugging log

        

    for some reason. But the acknowledgment was captured in the my approved achievement file, client.out.

        



  •     

  • It is absorbing to see that there was no cookie in the additional acknowledgment and

        

    third response. My assumption is that JSP server saw the affair ID in the additional request

        

    and third request, so there was no charge to put the affair ID as a cookie in the responses.

        



  •     



    



    



    

 


Tags: simple, agent, client, server, content, third, color, reading, cookie, session, notes, tutorial, tutorials, second, response, cookies, object, print

 request, cookie, protocol, useragent, cookies, response, localhost, regform, print, submit, header, color, client, simple, session, second, jsessionid, server, extract, input, debugging, content, checking, moved, previous, gmtserver, length, apache, third, responselwp, regdone, 0connection, coyote, proxy, local, response, blue&, none&, mike&, notes, proxiedlwp, libwww, agent, 8080user, 0host, reading, , http request, protocol http, regform jsp, lwp useragent, request get, cookie header, useragent request, request http, request lwp, cookie jar, type text, http localhost, cookies add, localhost 8080, extract cookies, req res, jsp server, < input, input type, 302 moved, lwp protocol, jsp name, header checking, request reading, cookie jsessionid, responselwp protocol, dec 2002, reading responselwp, text size, regdone jsp, jsp color, response was, simple response, request simple, apache coyote, libwww perl, gmtserver apache, need proxy, pass none&, none& color, color blue&, blue& submit, mike& pass, name mike&, http cookies, jar extract, cookies res, print response, print res, proxiedlwp protocol, 0host localhost, localhost 8080user, 8080user agent, proxy not, reg client, useragent simple, simple request, useragent need, agent libwww, protocol http request, http request http, http localhost 8080, < input type, lwp protocol http, cookie header checking, agent libwww perl, 8080user agent libwww, localhost 8080user agent, 0host localhost 8080user, http request reading, responselwp protocol http, useragent request simple, request simple response, type text size, input type text, proxiedlwp protocol http, gmtserver apache coyote, request reading responselwp, reading responselwp protocol, mike& pass none&, pass none& color, useragent need proxy, jar extract cookies, name mike& pass, jsp name mike&, none& color blue&, useragent simple request, lwp useragent simple, color blue& submit, jsessionid 887896c93dfff372eb38818bf9f68db2cookie2 version, jsessionid 887896c93dfff372eb38818bf9f68db2http cookies, tutorials tutorial notes, 51cookie jsessionid 887896c93dfff372eb38818bf9f68db2cookie2, header checking cookie, 1lwp protocol http, closelwp protocol http, 302 moved temporarily, 0connection closelwp protocol, localhost 8080 regdone, version 1lwp protocol, cookie jsessionid 887896c93dfff372eb38818bf9f68db2http, 887896c93dfff372eb38818bf9f68db2cookie2 version 1lwp, 200 oklwp protocol, jstl tutorials tutorial, type text html, blue& submit submit, lwp useragent object, localhost 8080 regform, text html charset, utf 8content length, byteslwp useragent request, res request cookie, protocol collect read, oklwp protocol collect, res & dump, new http request,

Share JSP and JSTL Tutorials - Tutorial Addendum - JSP Sessions and Debugging:
Digg it!   Google Bookmarks   Del.icio.us   Yahoo! MyWeb   Furl  Binklist   Reddit!   Stumble Upon   Technorati   Windows Live   Bookmark

Text link code :
Hyper link code:

Also see ...

Permalink
Article In : Computers & Technology  -  jsp