- 

  

 package Servlet; 

 import javax.servlet.http.HttpServlet; 

 import java.io.IOException; 
 import java.io.PrintWriter; 

 import javax.servlet.RequestDispatcher; 
 import javax.servlet.ServletConfig; 
 import javax.servlet.ServletContext; 
 import javax.servlet.ServletException; 
 import javax.servlet.http.HttpServletRequest; 
 import javax.servlet.http.HttpServletResponse; 

 import utility.*; 

 /** 
  * Servlet Class 
  * 
  * @web.servlet              name="RealEstate" 
  *                           display-name="Name for RealEstate" 
  *                           description="Description for RealEstate" 
  * @web.servlet-mapping      url-pattern="/RealEstate" 
  * @web.servlet-init-param   name="A parameter" 
  *                           value="A value" 
  */ 
 public class RealEstateServlet extends HttpServlet { 

  	 public RealEstateServlet() { 
  	  	 // TODO Auto-generated constructor stub 
  	 } 

  	 protected void doGet(HttpServletRequest req, HttpServletResponse resp) 
  	  	 throws ServletException, 
  	  	 IOException { 
  	  	 // TODO Auto-generated method stub 
  	  	 double len1=Double.parseDouble(req.getParameter("l1")); 
  	  	 double len2=Double.parseDouble(req.getParameter("l2")); 	  	  
  	  	 double breadth1=Double.parseDouble(req.getParameter("b1")); 
  	  	 double breadth2=Double.parseDouble(req.getParameter("b2")); 
  	  	 String choice=req.getParameter("ch"); 
         PrintWriter pw=resp.getWriter(); 
  	  	 Plot1 p1=new Plot1(); 
  	  	 p1.setLen1(len1); 
  	  	 p1.setBreadth1(breadth1); 
  	  	 Plot2 p2=new Plot2(); 
  	  	 p2.setLen1(len2); 
  	  	 p2.setBreadth2(breadth2); 
         double d1=p1.calcArea(); 
         double d2=p2.calcArea(); 
  	  	 ServletConfig conf=getServletConfig(); 
  	  	 int limit=Integer.parseInt(conf.getInitParameter("minGovLimit")); 
  	  	 String set=""; 
  	  	 if(d1d2) 
          	 {        
          	  	 set=set+"The area of bigger plot is "+ d1; 
          	 } 
          	 else  
          	 { 
          	  	 set=set+" The area of bigger plot is  "+ d2; 
  	          
  	         } 
         } 
         else if (choice.equals("Small")) 
         { 
          	  	 if (d1>d2) 
          	  	 {        
          	  	  	 set=set+" The area of smaller plot is "+ d2; 
          	  	 } 
          	  	 else  
          	  	 { 
          	  	  	 set=set+" The area of smaller plot is "+ d1; 
              
          	  	 } 
          } 
  	  	  req.setAttribute("choice",choice); 
          req.setAttribute("ans",set); 
  	  
         
         RequestDispatcher rd=req.getRequestDispatcher("result.jsp"); 
         rd.include(req, resp); 
  	  	  
  	 } 
  	  

  	 protected void doPost(HttpServletRequest req, HttpServletResponse resp) 
  	  	 throws ServletException, 
  	  	 IOException { 
  	  	 // TODO Auto-generated method stub 
  	  	 doGet(req,resp); 
  	 } 

 } 
 - 

  
 package utility; 

 public class Plot1 { 
  	 private double len1; 
  	 private double breadth1; 
  	  
  	 public Plot1() 
  	 {} 
  	 public double getBreadth1() { 
  	  	 return breadth1; 
  	 } 
  	 public void setBreadth1(double breadth1) { 
  	  	 this.breadth1 = breadth1; 
  	 } 
  	  
  	 public double getLen1() { 
  	  	 return len1; 
  	 } 
  	 public void setLen1(double len1) { 
  	  	 this.len1 = len1; 
  	 } 
  	  
  	 double area; 
  	 public double calcArea() 
  	 { 
  	 area=len1*breadth1; 
  	 return area; 
  	 } 
 }