Showing posts with label Factorial Solver in JSTL and JSP. Show all posts
Showing posts with label Factorial Solver in JSTL and JSP. Show all posts

Sunday, May 29, 2016

Factorial Solver in JSTL and JSP

A simple program that I wrote that we ask the user to give a number and then the program will compute the factorial value of the number using JSP and JSTL. The code is very simple and easy to understand.

 Add me at Facebook my address is jakerpomperada@gmail.com and jakerpomperada@yahoo.com

My mobile number here in the Philippines is 09173084360



Sample Program Output


Program Listing

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<html>
<head>
<title> Factorial Solver  Solver in JSTL and JSP</title>
</head>
<style>
body 
{
font-family:arial;
font-weight:bold; 
size:12px;
color:blue;
}
</style>
<body>
  <h2> Factorial Solver in JSTL and JSP </h2>
  <br>
  <form method="post">
      Enter a number &nbsp; &nbsp;
    <input type="text" name="number"  size="3" value="<c:out value="${param.number}"/>" autofocus/><br>
      <br> <br>
     <input type="submit" value="Compute Factorial"  title="Click here to findout the factorial value." />
     <br />
    </form>
<c:if test="${pageContext.request.method=='POST'}">

         <%!
    int numberfactorial(int number)
    {
        if (number == 1) {
            return number;
        }
        else {
            return number * numberfactorial(number - 1);
        }
    }
    %>
<%int no = Integer.parseInt(request.getParameter("number"));%>
    <%
        out.println("The factorial  of " + no + " is " + numberfactorial(no)+ ".");
    %>
  

</c:if>
</body>
</html>