×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

simple jsp function calling question

simple jsp function calling question

simple jsp function calling question

(OP)
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)

RE: simple jsp function calling question

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

RE: simple jsp function calling question

(OP)
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?

RE: simple jsp function calling question

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

RE: simple jsp function calling question

(OP)
thanks. I'll try that. Regards, Simon

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close