This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js and have Paul Jensen on-line!
See this thread for details.
Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

problem with Nper class  RSS feed

 
adam caine
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am new to JSP, have only previously worked in asp.

Can anybody point me in the right direction as to why it wont work?

Any help is greatly appriciated.

---
<%@ page import="java.lang.Object"%>
<html>
<body>
<%!
public class Nper extends Object
{
Nper tmpPeriod = new Nper();
Nper getPeriod()
{
double rate = 0.708;
double curBal = 300000;
double payment = -3000;
tmpPeriod = new Nper(rate,curBal,payment,0);
return tmpPeriod;
}
}
%>

Repayment period = <%=getPeriod%> (months).
</body>
</html>
 
Tim Baker
Ranch Hand
Posts: 541
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Quite a lot of errors there.

First I Would say Nper should be a bean withing it's own .java file.

Second you have a property that is trying to be another instance of the same class. I don't know what you are trying to do there.

Third you method getPeriod() is returning an instance of the same class.

(I think points 2 & 3 just mean you need to lookup how to use constructors)

Finaly you are trying to create an object outside of the %> tags, which means you are just printing out HTML. What you probably want to do is create a new Nper class, and then call some function on it to print out the value from it as HTML

 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You don't need to (and can't) declare a class inside a JSP.
The container you're using will convert your JSP into a Java Servlet class for you.

If you have no experience in Java, I recommend following a few tutorials before delving into servlets and JSP.
The "First Cup Of Java" tutorial on http://java.sun.com is very good.

Once you've done that, take a look at http://pdf.coreservlets.com.
It's a great book and can be download for free in PDF form.
There is also a second edition to the book that is more current (you'll have to buy that one).

On the surface, JSP looks a lot like ASP or PHP but there are some very important differences that can get you into trouble if you don't understand them. Threading, is number one.
Learning servlets first, makes the underlying concepts behind JSP much easier to understand.
[ June 29, 2005: Message edited by: Ben Souther ]
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!