This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Servlets and the fly likes JSP access Servlet's data ?? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "JSP access Servlet Watch "JSP access Servlet New topic
Author

JSP access Servlet's data ??

Jimmy Hu
Greenhorn

Joined: Feb 05, 2001
Posts: 17
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


Jimmy
Ashwin Desai
Ranch Hand

Joined: Jul 17, 2000
Posts: 124
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

Joined: Feb 05, 2001
Posts: 17
Ashwin,
Thanks a lot. I will try it.
------------------
Jimmy
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JSP access Servlet's data ??
 
Similar Threads
Passing Variable from JSP to JAVA
forward problem in JSP
Data Access Object
How to restore form Data in Java
Servlet communication with portlet