For Programmers: Free Programming Magazines  


Home > Archive > Java Beans > June 2004 > integrating JSP with Servlets









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author integrating JSP with Servlets
Amy Johnson

2004-06-03, 7:13 pm

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

2004-06-03, 7:13 pm

Amy Johnson (amy_johnson@dnr.state.ak.us) wrote:
: 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

2004-06-03, 7:13 pm

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
>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


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com