• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Cookie

 
Ranch Hand
Posts: 664
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!

 
Ranch Hand
Posts: 368
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please provide directory structure for this web app.
 
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 437
Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Nabila.

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

and add following entries for web.xml
 
Nabila Mohammad
Ranch Hand
Posts: 664
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 437
Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 664
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 437
Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 664
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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)
 
Ranch Hand
Posts: 257
Hibernate Oracle Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.



 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic