Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

simple jsp function calling question

Status
Not open for further replies.

simonTheTraveller

Programmer
Jun 29, 2006
16
0
0
GB
Hi all. I'm trying to call a jsp function from a jsp page. The jsp function resides inside a class held in another location. At the top of the jsp page i've used the line:
<jsp:useBean id="liSummary" scope="session" class="mm.mmLifeInsSummary"></jsp:useBean>

to instantiate the class and be called liSummary
inside liSummary is a function called calcNeededLi
this looks like this:

public double calcNeededLi(int term,double income){
double factors[] = {0.0,0.0,0.0,0.0,0.0,4.5,5.28,6.03,6.76,7.44,8.1};
double theFactor = factors[term];
double neededLi = theFactor * income;

return neededLi;
}

from the main jsp page I'm trying to call the function but with no luck using the following line:

liSummary.calcNeededLi((Integer)session.getAttribute("value1"),(Double)session.getAttribute("value2
"))

however, this outputs the error message:

java.lang.ClassCastException: java.lang.String

Anybody have any idea why? Thanks (in advance)
 
I bet for the values you're getting from the session, value1 and value2, they're not Integer or Double, and the cast is barfing.

How are you storing those values in the session?

Cheers,
Dian
 
the session variable has been stored simply by setting it to the value of a text field from a previous page like this:

session.setAttribute("value1",request.getParameter("previousTextField"));


Is this a problem?
 
Then you're storing Strings, not Integers or Doubles.

You need to retrieve them as String and the obtain the value by calling Integer.parseInt or Double.parseDouble.

cheers,
Dian
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top