• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

problem with Nper class

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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>
 
Ranch Hand
Posts: 541
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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

 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Politics n. Poly "many" + ticks "blood sucking insects". Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic