• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Servlets and JSP

 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi
how to pass objects from one servlet to another servlet.
please give me small example.
Thankyou
regards
Ramya
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13055
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One of the easiest ways to pass an object around between servlets and Javaserver Pages is with a Session (javax.servlet.http.HttpSession)
Sessions are objects that are managed by the servlet engine and are identified by a unique "cookie" value. You can attach an arbitrary object to a session in one servlet with:
session.setAttribute("objname", theObj);
and get it back with
notherObj = (objtype)session.getAttribute("objname");
Use the HttpRequest method getSession() to get the
session associated with a request.
NOTE: the user's browser must be set to accept cookies.

------------------
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic