• Post Reply Bookmark Topic Watch Topic
  • New Topic

Servlet forwarding  RSS feed

 
Zein Nunna
Ranch Hand
Posts: 245
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys,

I have an issue; I'm trying to create a bean inside a servlet, populate it and then forward that to a JSP, for it to extract data only for a request.

I have a JSP from which I'm being directed to a servlet via a link (this is fine).

Inside the servlet I need to do some computation first, if all is good, create a bean with some data inside it and forward to some JSP - the data is only 'request' scope, hence I did the following



So in this JSP when I try to



This returns null.

However when I use the request dispatcher and forward



I am able to access the data from the bean. My question is why??
Is rd.forward the only way of creating a bean and then forwarding from a servlet.

Thanks in advance, sorry for the laborious explanation
Zein
[ February 08, 2007: Message edited by: Bear Bibeault ]
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A redirect causes the browser to initiate a new request. Hence any scoped variables placed upon the first request go out of scope when the first response is returned to the client.
[ February 08, 2007: Message edited by: Bear Bibeault ]
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You may find this article helpful.
 
Zein Nunna
Ranch Hand
Posts: 245
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much Bear.

Took me sometime to work that out the hard way One way or another it's quite satisfying getting to the bottom problems like this.

Article is great.
Zein

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!