source file name: sqcubefact.html
<html>
<head>
<title>TODO supply a title</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width">
</head>
<body>
<form action="http://localhost:8080/JspWebApplication/sqcubebeans.jsp" method="post" >
enter any number:
<input type="text" name="no" >
<br>
<br>
<input type="submit" >
</form>
</body>
</html>
output:
source file name: sqcubebeans.jsp
<%! int n; %>
<%
n=Integer.parseInt(request.getParameter("no"));
out.println("<h2>given no is: "+n);
%>
<jsp:useBean id="beans" class="mybeans.sqcubefact" />
<%
out.println("<br><h2>Square of no : "+beans.square(n));
out.println("<br> <h2>Cube of no : "+beans.cube(n));
out.println("<br> <h2>Factorial value of no : "+beans.fact(n));
%>
source file name: sqcubefact.java
Java-Bean methods code
package mybeans;
public class sqcubefact
{
public int square(int n)
{
return n*n;
}
public int cube(int n)
{
return n*n*n;
}
public int fact(int n)
{
int f=1;
for(;n>0;n--)
f=f*n;
return f;
}
}
0 Comments
Post a Comment