This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Cookie Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Cookie" Watch "Cookie" New topic
Author

Cookie

Nabila Mohammad
Ranch Hand

Joined: Nov 05, 2007
Posts: 661
Hi!

I am trying to run this program of cookies mentioned in HFSJ and I am not sure how it is supposed to run (programatically).
Tried running it from the way i understood , but i am getting "Resourse not found error".
I think some file is incomplete or something is missing..

Anyway these are my codes.

CookieTest.java


CheckCookie.java


This are the additional files i wrote starting with web.xml (may or maynot be incomplete)




My form.html



My cookieresult.jsp (the view)





Can some one please help me in running this program and how the servlets are being called....

Thanks!


The future belongs to those who believe in the beauty of their dreams.Dream BIG!
Shailesh Narkhede
Ranch Hand

Joined: Jul 10, 2008
Posts: 368
Please provide directory structure for this web app.


Thanks,
Shailesh
Hasnain Javed Khan
Ranch Hand

Joined: Nov 23, 2007
Posts: 73
Hi Nabila.

but i am getting "Resourse not found error".


When do you get the above error ? when accessing /cooky.do, form.html or cookieresult.jsp ?

Kind Regards.
Hasnain.
Chinmaya Chowdary
Ranch Hand

Joined: Apr 21, 2008
Posts: 432
Hi Nabila.

Inorder to see the affect, modify cookieresult.jsp like this

and add following entries for web.xml
Nabila Mohammad
Ranch Hand

Joined: Nov 05, 2007
Posts: 661
Thanks...
That worked...

I didn't know , after the view another servlet would be invoked on clicking...
Always thought the view would be always the last thing...

One more thing...
Where is the out put of CookieTest..java displayed

ie.
out.println(name);
out.println("In Cookie Test");

I dont see anything in the stout file in my log....
Chinmaya Chowdary
Ranch Hand

Joined: Apr 21, 2008
Posts: 432
Hi Nabila.
Where is the out put of CookieTest..java displayed

ie.
out.println(name);
out.println("In Cookie Test");

I dont see anything in the stout file in my log....


In CookieTest.java, there is forward(request,response) method of RequestDispatcher. We know before forwarding, if any data(here 'name', 'In Cookie Test') present in buffer, that will be cleared. For more information see RequestDispatcher's forward method.

Nabila Mohammad
Ranch Hand

Joined: Nov 05, 2007
Posts: 661
I read the documentation but i still didn't get it.

Wouldn't the out put be printed at all.. , Or does it get printed and then deleted (Cleared) when the forward method is executed.
Chinmaya Chowdary
Ranch Hand

Joined: Apr 21, 2008
Posts: 432
Hi Nabila.
Wouldn't the out put be printed at all.. , Or does it get printed and then deleted (Cleared) when the forward method is executed.

No, it will not print. Before forward, the name that is got from form and 'In Cookie Test' will write to the buffer. Before forwarding, container will clear the buffer.
Nabila Mohammad
Ranch Hand

Joined: Nov 05, 2007
Posts: 661
k..Thanks , Chinmaya!

One more thing...

When i write "out.println(...)" It gets written in the buffer.
And when i use forward() , the buffer gets cleared.

But what happens when i don't use forward()
When does it actually print in the stdout file from the buffer. (at what point)
Salil Vverma
Ranch Hand

Joined: Sep 06, 2009
Posts: 253

Hey Nabila ,

When i write "out.println(...)" It gets written in the buffer.
And when i use forward() , the buffer gets cleared.

But what happens when i don't use forward()
When does it actually print in the stdout file from the buffer. (at what point)


Looks like you are getting confused with out and stdout. As you can see in the following line that out is PrintWriter object to the response, out.println("text") will always write the output in the response to the browser. To bring specific thing in stdout, you can either use System.out.println("text") ; function in your code or use specific logger api (like log4j)



I hope this would clear your confusion.




Regards
Salil Verma
 
wood burning stoves
 
subject: Cookie
 
Similar Threads
Question regarding : cookie.getMaxAge()
HFSJ book: Cookie example chapter 6 plz Help :(
JSp with Cookies HFSJ pg 386
Cookies example in HFSJ
Testing Cookies