Logo 
Search:

Java Articles

Submit Article
Home » Articles » Java » Remote Method InvocationRSS Feeds

Servlet which takes input from an HTML client page and calculates and outputs the premium amount

Posted By: Charlie Evans     Category: Java     Views: 4814

servlet which takes input from an HTML client page and calculates and outputs the premium amount

Code for Servlet which takes input from an HTML client page and calculates and outputs the premium amount in Java

----------------------------------------------------------------------------------
                    HTML File
----------------------------------------------------------------------------------
<html>
<head Premium Details>
<title Premium Details>
</title>
</head>

<body>
<form name="form2" method="GET" action="/q2/try2.do">
<BR><h1>Insurance Premium</h1><br>

<input type=radio value="25Years"checked=True name=optyr>25 Years
<input type=radio value="30Years" name=optyr>30 Years
<br><br>

<input type=radio value="House Wife"checked=True name=optw>House Wife
<input type=radio value="Working Woman" name=optw>Working Woman
<br><br>

<input type=submit value=SUBMIT>
</form>
</body>
</html>

-------------------------------------------------------------------------------------------------
                    Java File
-------------------------------------------------------------------------------------------------

import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;

publicclass Insurance extends HttpServlet
{
       publicvoid doGet(HttpServletRequest req, HttpServletResponse res) throws 
       IOException, ServletException
       {
               PrintWriter out=res.getWriter();
               double amt=0.0, total_amt=0.0;

               out.write("<html>");
               out.write("<head>");
               out.write("<title>");
               out.write("</title>");
               out.write("<body>");
               
               String yr=req.getParameter("optyr");
               if(yr.equalsIgnoreCase("25Years"))
               {
                      amt=4000;
               }               
               if(yr.equalsIgnoreCase("30Years"))
               {
                      amt=3000;
               }               
               String hf="House Wife";
               String status=req.getParameter("optw");

               out.write("<h1>Insurance Premium Details</h1><br><br>");

               if(hf.equalsIgnoreCase(status))
               {
                       total_amt=amt-((5*amt)/100);
               }
               else
               {
         total_amt=amt;
               }   
               
               out.write("<br><br>");
               out.write("<br><br>");               
               out.write("Total Amount of Insurance Premium : "+total_amt);  
               out.write("</body>");
               out.write("</html>");        
               out.close();
        }
}    
  
Share: 



Charlie Evans
Charlie Evans author of Servlet which takes input from an HTML client page and calculates and outputs the premium amount is from London, United Kingdom.
 
View All Articles

Related Articles and Code:


 

Other Interesting Articles in Java:


 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!