Java Servelts and Persistent Variables

N

Nino Skilj

I'm not so great with the whole Java thing, but am trying something I
cannot figure out.

I have three servlet classes, DisplayData, DoCalculations, and
SpecialCases.
DisplayData calls DoCalculations.

DoCalculations takes a lot of information from a database, sorts
through it and runs all the business logic to figure out what the best
possible schedules are possible for a given month. Well, in that month
there are special cases (where certain events cannot occur on certain
days for example). In these cases, SpecialCases is called (only where
needed) and refers to about 10 different methods (ex. notAvailSunday,
etc).

Anyways, each special case adjusts anywhere from 2-3 different arrays
of information. This does not allow me to simply return(array[][]).
So, is there a way for SpecialCases to recognize variables defined in
DoCalculations? Something like a grand global variable? What would be
the approach?

Thanks,
Nino Skilj
 
D

Dirk Michaelsen

Hi,
Anyways, each special case adjusts anywhere from 2-3 different arrays
of information. This does not allow me to simply return(array[][]).
So, is there a way for SpecialCases to recognize variables defined in
DoCalculations? Something like a grand global variable? What would be
the approach?

before you forward the request to the SpecialCases servlet add the
object to the request stream:

request.getSession().addAttribute("myarray",the_array);


In the SpecialCases servlet you get the object from the request
stream:

array_type the_array = (array_type)request.getAttribute("myarray");

cu
Dirk
 
R

Ryan Stewart

Dirk Michaelsen said:
Hi,
Anyways, each special case adjusts anywhere from 2-3 different arrays
of information. This does not allow me to simply return(array[][]).
So, is there a way for SpecialCases to recognize variables defined in
DoCalculations? Something like a grand global variable? What would be
the approach?

before you forward the request to the SpecialCases servlet add the
object to the request stream:

request.getSession().addAttribute("myarray",the_array);

In the SpecialCases servlet you get the object from the request
stream:

array_type the_array = (array_type)request.getAttribute("myarray");
You can't put something in the session and get it from the request. You also
don't "add" attributes. You want either
request.setAttribute(...);
request.getAttribute(...);

or

request.getSession().setAttribute(...);
request.getSession().getAttribute(...);
 
D

Dirk Michaelsen

Hi Ryan,

you are right, my apologies. What I ment was this:
request.getSession().setAttribute(...);
request.getSession().getAttribute(...);

cu
Dirk
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,276
Latest member
Sawatmakal

Latest Threads

Top