• 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

Wrong output. Whats wrong??

 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I have two Servlets. The first one is :



For the above servlet I get the following output in the browser:



I get the following output for the above servlet


You are now in Servlet 6 The time in Servlet 5 is : null



Why is it showing null as the value??

I know this whole thing can be easily done using ServletContext but I'm just trying it out using include.

Thanx in advance

[ September 26, 2005: Message edited by: Mamu Jan ]

[ Broke up long line and fixed typo in title ]
[ September 27, 2005: Message edited by: David O'Meara ]
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If the servlets are run as a result of different requests, then the attribute you write in one will not exist in the other. You either need to place it on the session (not always a good idea), or write the value to the first page and get it to pass it back to the second servlet.

Dave
 
Mamu Jan
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


or write the value to the first page and get it to pass it back to the second servlet.



How can I do this?? Can anyone show me an example??
[ September 27, 2005: Message edited by: Mamu Jan ]
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The trick is to get the client to pass the information back to the Servlet, at which point it becomes available in the request. It gets passed as a parameter in the request, not an attribute.


[ September 27, 2005: Message edited by: David O'Meara ]
 
Ranch Hand
Posts: 230
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear David,

Can you please explain, how in this code, you see a new request and response object. We have passed the same request and response objects from servlet5 to servlet6. Right?

I have a similar example tried out in my PC and it worked fine that time. I have done chaining between 3 servlets and it worked perfectly fine.

Putting the code here will bloat the entire write up. So stopping from doing that.

I feel that the code should work fine!

Please explain, if otherwise!

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