Sunday, 15 May 2022

Advance Java-slip2a-Write a JSP program to check whether given number is Perfect or not. (Use Include directive).

Write a JSP program to check whether given number is Perfect or not. (Use Include  directive).

 <html>

<body>

<form action="http://localhost:8080/perfect.jsp" method="post">

Enter any no:<input type="text" name="t1" >

<br>

<input type="submit" >

</form>

</body>

</html>

 

Perfect.jsp

<%@ page language="java" %>


<html>


    <body>

 <%


int n=Integer.parseInt(request.getParameter("t1"));

out.println(" given number is: "+n);

int sum = 0;

for(int i = 1; i < n; i++)

{

if(n % i == 0)

{

sum = sum + i;

}

}

if(sum == n)

{

out.println("<br>"+n+" is Perfect no.");

}

else

{

out.println("<br>"+n+" is not Perfect");

}  

    %>      


</body></html>