Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Treating servlet as a Bean

 
Bala Krishna
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is this possible? One of the solutions to the problem I am trying to solve demands this approach. I want to be able to call some methods in the servlet from JSPs, not just sending HTTP requests via forward, or sendredirect. The only hitch seems to be getting a handle to the instance of the servlet. Can some one please shed some light on how this can be done? Thanks.
-Bala
 
Frank Carver
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can do this by having the servlet put itself into the session, but I think it would be a very dangerous and un-intuitive thing to do.
Why not create another class which does what you want, and call it both from your servlet and from the JSP?
 
ruilin yang
Ranch Hand
Posts: 334
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When I use a servlet, I only use it to handling request and response (collecting inser input to stuff beans, and direct tasks). Servlet can call othe help objects of other classes to perform certain task. My servlets normally only have two methods, doGet/doPost.
I think clean servlet is good design.
regards,
ruilin
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic