HTML TO SERVLET COMMUNICATION(BANK DATA) PROGRAM

bankentryform.html

<html>
<body>
<form action="bankform" method="get">
<h3>
Enter ACCOUNT NO: <input type="text" name="ACC_NO"><br><br>

Enter CUSTOMER NAME: <input type="text" name="CUST_NAME"><br><br>

Enter ACCOUNT TRANSACTION DATE:<input type="text" name="TRANS_DATE"><br><br>

Enter TRANSACTION TYPE(D-DEPOSIT/W-WITHDRAWL):<input type="text" name="TRANS_TYPE"><br><br>

Enter TRANSACTION AMOUNT:<input type="text" name="TRANS_AMT"><br><br>

Enter  AMOUNT IN THE ACCOUNT:<input type="text" name="AMT"><br><br>

<input type="submit" value="SUBMIT">

</h3>
</form>
</body>

</html>

bankform.java

import java.io.*;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class bankform extends HttpServlet{

public void doGet(HttpServletRequest request,HttpServletResponse response)throws IOException,ServletException{

response.setContentType("text/html;charset=UTF-8");

PrintWriter out=response.getWriter();

String s1=request.getParameter("TRANS_TYPE");

int m=Integer.parseInt(request.getParameter("TRANS_AMT"));

int c=Integer.parseInt(request.getParameter("AMT"));

if (s1.equals("D")){
        c=c+m;
        out.println("<h1>"+"Amount in the Account="+c+"</h1>");
}

if (s1.equals("W")){
        if (m > c){
        out.println("<h1>"+"SORRY!!!!!! LESS AMOUNT IN YOUR ACCOUNT"+"</h1>");
        }        
        else{
        c=c-m;
        out.println("<h1>"+"Amount in the Account="+c+"</h1>");
        }//ELSE
        
}// OUTER IF LOOP

}//DO GET METHOD

}//CLASS

web.xml
<?xml version="1.0" encoding="UTF-8"?>

<web-app version="3.0">

<servlet>
  <servlet-name>bankform</servlet-name>
  <servlet-class>bankform</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>bankform</servlet-name>
<url-pattern>/bankform</url-pattern>
</servlet-mapping>

</web-app>

OUTPUT:

transaction type:deposit





transaction type:withdrawl







No comments:

Post a Comment