Monday, November 5, 2012

Calculator useing jsp

Cal.jsp  
 <%--   
   Document  : Cal  
 --%>  
 <%@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>Calculator</title>  
   </head>  
   <body>  
     <form metod="get" action="Cal1.jsp">  
     Value1:<input type="text" name="v1"/><br/>  
     Value2:<input type="text" name="v2"/><br/>  
     Opration:<select name="op">  
     <option>+</option>  
     <option>-</option>  
     <option>*</option>  
     <option>/</option>  
     </select><br/>  
     <input type="submit" name="b" value="ok"/>  
   </form>  
   </body>  
 </html>  


 Cal1.jsp  
 <%--   
   Document  : Cal1  
 --%>  
 <%@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>  
     <%! int ans; %>  
     <% int s=Integer.parseInt(request.getParameter("v1"));  
     int r=Integer.parseInt(request.getParameter("v2"));  
     String op1=request.getParameter("op");  
       if(op1.equals("+")){  
       ans=s+r;  
       }  
       if(op1.equals("-")){  
       ans=s-r;  
       }  
       if(op1.equals("*")){  
       ans=s*r;  
       }  
       if(op1.equals("/")){  
        ans=s/r;  
       }%>  
       <h1> answer is : <%=ans%> </h1>   
   </body>  
 </html>  







No comments:

Post a Comment