Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JSP access Servlet's data ??  RSS feed

 
Jimmy Hu
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I'm new on JSP and Servlet.
One servlet generated an object and put it in ServletContext by
: getServletContext().getAttribute("examples.myObject");
Now a JSP wants to access this object(reference) and get some
internal data of this object.
How do I implement this?
Thanks for your kind help.
Jimmy
------------------
Jimmy
 
Ashwin Desai
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
If you use the servlet context to store state (data) in a servlet, you can use the "application" variable in JSP to access it, provided the servlet and the JSP are in the same Context, i.e. are on the same server running in the same webserver and same JVM.
Another way of doing this would be to use the "session" attribute of the JSP page, if your data is valid for a client session.
In Servlet:
session.putValue("..", "..);
In JSP:
session.getValue("...");
Hope this helps.
Ashwin.
 
Jimmy Hu
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ashwin,
Thanks a lot. I will try it.
------------------
Jimmy
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!