Java Blog

 
 
 
----------------------------------------------------------------------------------
                    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.*;

public class Insurance extends HttpServlet
{
       public void 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();
        }
}