This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JSP access Servlet's data ??

 
Jimmy Hu
Greenhorn
Posts: 17
  • 0
  • 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
  • 0
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ashwin,
Thanks a lot. I will try it.
------------------
Jimmy
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic