I am trying to understand how to calculate data in a servlet, store it
in a bean, then access that data from a JSP. I found an example in a
book, "Core Servlets and JavaServer Pages" (first edition) that says to
do the following in the originate servlet:
Type1 value1 = computeValueFromRequest(request);
getServletContext().setAttribute("key1", value1);
Then the JSP would access the data by setting up the jsp:useBean as follows:
<jsp:useBean id="key1" class="Type1" scope="application" />
I don't really understand this. I'm assumins computeValueFromRequest()
is a servlet method, but I can't find it anywhere. Does anyone have any
ideas?
Thanks much,
Amy
Malcolm Dew-Jones - 01 Jun 2004 23:57 GMT
: I am trying to understand how to calculate data in a servlet, store it
: in a bean, then access that data from a JSP. I found an example in a
: book, "Core Servlets and JavaServer Pages" (first edition) that says to
: do the following in the originate servlet:
: Type1 value1 = computeValueFromRequest(request);
: getServletContext().setAttribute("key1", value1);
: Then the JSP would access the data by setting up the jsp:useBean as follows:
: <jsp:useBean id="key1" class="Type1" scope="application" />
: I don't really understand this. I'm assumins computeValueFromRequest()
: is a servlet method, but I can't find it anywhere. Does anyone have any
: ideas?
It is just a made up name for the example.
They could have said something like this...
String value1 = "This is an example value";
getServletContext().setAttribute("key1", value1);
--
(Paying) telecommute programming projects wanted. Simply reply to this.
Dirk Michaelsen - 02 Jun 2004 09:42 GMT
Hi Amy,
I am doing it this way (you can also use any other type than String):
In the servlet do this:
String anything = "Hello World";
request.getSession().setArrtibute("aName",anything);
In the JSP do this:
String anything = (String)session.getAttribute("aName");
cu
Dirk
>I am trying to understand how to calculate data in a servlet, store it
>in a bean, then access that data from a JSP. I found an example in a
[quoted text clipped - 15 lines]
>
>Amy