Second Lesson on JSP
Now we are going to calculate "simple interest". First of all we have to create html page like ::
The code for this page ::
<%--
Document : interest
Created on : 30 Oct, 2012, 10:30:44 PM
Author : NESTED CODE
--%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
<script>
function checkNumber(f)
{
var a = window.event.keycode;
if(!(a>=48 && a<=57))
alert("Type a number between 0 and 9")
}
</script>
</head>
<body><br><br><center>
<form action="intjsp.jsp "><pre>
<h1>Principal :: <input type=text name=principle value=0 onkeypress="checkNumber(this.form)" ><br>
No. of Years :: <input type=text name=year value=0 onkeypress="checkNumber(this.form)" ><br>
Rate of Interest :: <input type=text name=interest value=0 onkeypress="checkNumber(this.form)" ><br>
<br>
<input type=submit value="Submit"></h1>
</pre></form></center>
</body>
</html>
Now we have to create the page "intjsp.jsp" to calculate interest
Code for this "intjsp.jsp" page ::
Document : intjsp
Created on : 30 Oct, 2012, 10:41:10 PM
Author : NESTED CODE
--%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body><br><br><center><pre><H1>
<%
String ns= request.getParameter("principle");
String ns1= request.getParameter("year");
String ns2= request.getParameter("interest");
int n1=Integer.parseInt(ns);
int n2=Integer.parseInt(ns1);
int n3=Integer.parseInt(ns2);
double si=((n1*n2*n3)/100);
double x;
x=n1+si;
%>
<%
out.println("Principal= "+n1);
out.println(" Years= "+n2);
out.println(" Rate of Interest= "+n3);
out.println("<br> ");
out.println(" Simple Interest= "+si);
out.println(" Simple Interest= "+x);
%>
</H1>
</pre>
</center>
</body> </body>
</html>
The Outpur will be like ::
Note : For any further query, write down in comments box. You have already finished your second lesson . Now go for the next lesson. Thank you.
Previous Lesson Next Lesson
horrible formatting
ReplyDeleteThanks for your comments! We are keep working to rectify formatting and stylesheet work. Hope you will like our page now- provides a better service.
DeleteWould you like to donate us with 50/- for better service ? please click the below URL -
https://imjo.in/t9cEFy
Thanks! Keep reading our blogs! Happy Reading!
Need a jsp program to calculate simple interest,accept values from the user and display result back to user
ReplyDeleteYes thats what is about this post. Send me your email id to get the complete code
ReplyDelete